답안 #1006381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1006381 2024-06-23T23:02:22 Z MilosMilutinovic Rima (COCI17_rima) C++14
14 / 140
131 ms 262144 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < n; i++) {
    reverse(s[i].begin(), s[i].end());
  }
  auto Can = [&](string s, string t) {
    if (s.size() > t.size()) {
      return false;
    }
    if (s.size() == t.size() && s > t) {
      return false;
    }
    int p = 0;
    while (p < (int) s.size() && s[p] == t[p]) {
      p += 1;
    }
    return p >= (int) t.size() - 1;
  };
  vector<vector<bool>> good(1 << n, vector<bool>(n));
  for (int i = 0; i < n; i++) {
    good[1 << i][i] = true;
  }
  for (int mask = 1; mask < (1 << n); mask++) {
    for (int i = 0; i < n; i++) {
      if ((mask >> i & 1) && good[mask][i]) {
        for (int j = 0; j < n; j++) {
          if (mask >> j & 1) {
            continue;
          }
          if (Can(s[i], s[j])) {
            good[mask | (1 << j)][j] = true;
          }
        }
      }
    }
  }
  int res = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    for (int i = 0; i < n; i++) {
      if (mask >> i & 1) {
        if (good[mask][i]) {
          res = max(res, __builtin_popcount(mask));
        }
      }
    }
  }
  cout << res << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 4952 KB Output isn't correct
2 Correct 58 ms 18772 KB Output is correct
3 Incorrect 50 ms 18888 KB Output isn't correct
4 Runtime error 32 ms 32336 KB Execution killed with signal 11
5 Runtime error 131 ms 262144 KB Execution killed with signal 9
6 Runtime error 10 ms 12020 KB Execution killed with signal 11
7 Runtime error 3 ms 1736 KB Execution killed with signal 6
8 Runtime error 2 ms 1468 KB Execution killed with signal 11
9 Runtime error 9 ms 7864 KB Execution killed with signal 11
10 Runtime error 2 ms 1632 KB Execution killed with signal 11