Submission #1476990
Source Code Expand
#include "bits/stdc++.h" using namespace std; #ifdef _DEBUG #include "dump.hpp" #else #define dump(...) #endif //#define int long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)(1e9) + 7; template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<bool> a(N); vector<int> A(K); rep(i, 0, K) { cin >> A[i]; A[i]--; a[A[i]] = true; } vector<string> S(N); rep(i, 0, N) { cin >> S[i]; } vector<int> L(N); string base = S[A[0]]; rep(i, 0, N) { int j = 0; for (; j < base.size() + 1; j++) { if (j == base.size() || S[i].size() <= j) break; if (S[i][j] != base[j]) break; } L[i] = j + 1; } dump(L); int l = 0, r = INF; rep(i, 0, N) { if (a[i]) { chmin(r, L[i] - 1); } else { chmax(l, L[i]); } } if (l <= r) cout << base.substr(0, l) << endl; else cout << -1 << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 検索 |
User | minaminao |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1314 Byte |
Status | AC |
Exec Time | 28 ms |
Memory | 6528 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, long.txt, long2.txt, sample1.txt, sample2.txt, sample3.txt, long.txt, long2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 2 ms | 384 KB |
in10.txt | AC | 2 ms | 384 KB |
in11.txt | AC | 4 ms | 896 KB |
in12.txt | AC | 1 ms | 384 KB |
in13.txt | AC | 2 ms | 512 KB |
in14.txt | AC | 2 ms | 384 KB |
in15.txt | AC | 1 ms | 384 KB |
in16.txt | AC | 1 ms | 256 KB |
in17.txt | AC | 2 ms | 384 KB |
in18.txt | AC | 2 ms | 384 KB |
in19.txt | AC | 3 ms | 896 KB |
in2.txt | AC | 4 ms | 896 KB |
in20.txt | AC | 2 ms | 512 KB |
in3.txt | AC | 21 ms | 6144 KB |
in4.txt | AC | 28 ms | 6528 KB |
in5.txt | AC | 2 ms | 384 KB |
in6.txt | AC | 1 ms | 256 KB |
in7.txt | AC | 1 ms | 384 KB |
in8.txt | AC | 4 ms | 896 KB |
in9.txt | AC | 28 ms | 6528 KB |
long.txt | AC | 2 ms | 512 KB |
long2.txt | AC | 8 ms | 2432 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |