AtCoder Beginner Contest 031

Submission #1672424

Source codeソースコード

// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int k, n;
  cin >> k >> n;
  vs v(n), w(n);
  rep(i, n) cin >> v[i] >> w[i];
  rep(t, pow(3, k)) {
    vi l(k);
    rep(i, k) l[i] = (int) (t / pow(3, i)) % 3 + 1;
    bool validLength = true;
    rep(i, n) {
      int ls = 0;
      for (char c : v[i]) ls += l[c - '1'];
      validLength &= ls == w[i].size();
    }
    if (!validLength) continue;
    vs s(k);
    bool validStr = true;
    rep(i, n) {
      int p = 0;
      for (char c : v[i]) {
        int tl = l[c - '1'];
        string x = w[i].substr(p, tl);
        if (s[c - '1'] == "" || s[c - '1'] == x) {
          s[c - '1'] = x;
        } else {
          validStr = false;
        }
        p += tl;
      }
    }
    if (!validStr) continue;
    for (auto x : s) cout << x << endl;
    return 0;
  }
}

Submission

Task問題 D - 語呂合わせ
User nameユーザ名 vvataarne
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 2258 Byte
File nameファイル名
Exec time実行時間 23 ms
Memory usageメモリ使用量 640 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample-01.txt,sample-02.txt,sample-03.txt,sample-04.txt
Subtask1 40 / 40 sample-02.txt,sample-03.txt,sample-04.txt,subtask1-01.txt,subtask1-02.txt,subtask1-03.txt,subtask1-04.txt,subtask1-05.txt,subtask1-06.txt,subtask1-07.txt,subtask1-08.txt,subtask1-09.txt,subtask1-10.txt,subtask1-11.txt,subtask1-12.txt,subtask1-13.txt,subtask1-14.txt,subtask1-15.txt,subtask1-16.txt,subtask1-17.txt,subtask1-18.txt,subtask1-19.txt,subtask1-20.txt
Subtask2 60 / 60 sample-01.txt,sample-02.txt,sample-03.txt,sample-04.txt,subtask1-01.txt,subtask1-02.txt,subtask1-03.txt,subtask1-04.txt,subtask1-05.txt,subtask1-06.txt,subtask1-07.txt,subtask1-08.txt,subtask1-09.txt,subtask1-10.txt,subtask1-11.txt,subtask1-12.txt,subtask1-13.txt,subtask1-14.txt,subtask1-15.txt,subtask1-16.txt,subtask1-17.txt,subtask1-18.txt,subtask1-19.txt,subtask1-20.txt,subtask2-01.txt,subtask2-02.txt,subtask2-03.txt,subtask2-04.txt,subtask2-05.txt,subtask2-06.txt,subtask2-07.txt,subtask2-08.txt,subtask2-09.txt,subtask2-10.txt,subtask2-11.txt,subtask2-12.txt,subtask2-13.txt,subtask2-14.txt,subtask2-15.txt,subtask2-16.txt,subtask2-17.txt,subtask2-18.txt,subtask2-19.txt,subtask2-20.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample-01.txt AC 3 ms 640 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt AC 1 ms 256 KB
sample-04.txt AC 1 ms 256 KB
subtask1-01.txt AC 1 ms 256 KB
subtask1-02.txt AC 1 ms 256 KB
subtask1-03.txt AC 1 ms 256 KB
subtask1-04.txt AC 1 ms 256 KB
subtask1-05.txt AC 1 ms 256 KB
subtask1-06.txt AC 1 ms 256 KB
subtask1-07.txt AC 1 ms 256 KB
subtask1-08.txt AC 1 ms 256 KB
subtask1-09.txt AC 1 ms 256 KB
subtask1-10.txt AC 1 ms 256 KB
subtask1-11.txt AC 2 ms 256 KB
subtask1-12.txt AC 1 ms 256 KB
subtask1-13.txt AC 1 ms 256 KB
subtask1-14.txt AC 1 ms 256 KB
subtask1-15.txt AC 1 ms 256 KB
subtask1-16.txt AC 2 ms 256 KB
subtask1-17.txt AC 1 ms 256 KB
subtask1-18.txt AC 1 ms 256 KB
subtask1-19.txt AC 1 ms 256 KB
subtask1-20.txt AC 1 ms 256 KB
subtask2-01.txt AC 7 ms 256 KB
subtask2-02.txt AC 5 ms 256 KB
subtask2-03.txt AC 15 ms 256 KB
subtask2-04.txt AC 15 ms 256 KB
subtask2-05.txt AC 18 ms 256 KB
subtask2-06.txt AC 8 ms 256 KB
subtask2-07.txt AC 22 ms 256 KB
subtask2-08.txt AC 4 ms 256 KB
subtask2-09.txt AC 23 ms 256 KB
subtask2-10.txt AC 23 ms 256 KB
subtask2-11.txt AC 22 ms 256 KB
subtask2-12.txt AC 12 ms 256 KB
subtask2-13.txt AC 19 ms 256 KB
subtask2-14.txt AC 18 ms 256 KB
subtask2-15.txt AC 16 ms 256 KB
subtask2-16.txt AC 4 ms 256 KB
subtask2-17.txt AC 2 ms 256 KB
subtask2-18.txt AC 23 ms 256 KB
subtask2-19.txt AC 23 ms 256 KB
subtask2-20.txt AC 23 ms 256 KB