Submission #1179554
Source Code Expand
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<string> #include<vector> #include<algorithm> #define rep(n) for(int i=0;i<n;i++) #define repp(j, n) for(int j=0;j<n;j++) #define reppp(i, m, n) for(int i=m;i<=n;i++) #define all(c) c.begin(), c.end() #define MOD 1000000007 #define MAX 1000000001 #define INF 1410065408 using namespace std; typedef long long ll; typedef pair<ll, ll> P; struct edge{int from, to; ll cost;}; int main(){ ll N, K; cin >> N >> K; if(N == K){ cout << ""; return 0; } vector<ll> an(K+1); vector<string> av, sv; rep(K) cin >> an[i]; int j = 0, k = 0; int min_length = 100000; rep(N){ string tmp; cin >> tmp; if(an[j] - 1 == i){ av.push_back(tmp); if(min_length > (int)av[j].length()){ min_length = (int)av[j].length(); } if(j < K) j++; }else{ sv.push_back(tmp); cin >> sv[k]; k++; } } string ans = "-1"; for(int i = min_length; i >= 0; i--){ string tmp = av[0].substr(0, i); bool flag = true; repp(j, K){ if(av[j].substr(0, i) != tmp){ flag = false; break; } } if(!flag) break; flag = true; repp(j, N-K){ if((int)sv[j].length() >=i){ if(sv[j].substr(0,i) == tmp){ flag = false; break; } } } if(flag){ ans = tmp; break; } } cout << ans; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 検索 |
User | Noimin |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1711 Byte |
Status | RE |
Exec Time | 139 ms |
Memory | 3708 KB |
Judge Result
Set Name | Sample | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | RE | 111 ms | 384 KB |
in10.txt | WA | 4 ms | 256 KB |
in11.txt | RE | 114 ms | 640 KB |
in12.txt | RE | 109 ms | 384 KB |
in13.txt | WA | 5 ms | 384 KB |
in14.txt | WA | 5 ms | 384 KB |
in15.txt | WA | 3 ms | 384 KB |
in16.txt | AC | 1 ms | 256 KB |
in17.txt | RE | 108 ms | 384 KB |
in18.txt | RE | 108 ms | 384 KB |
in19.txt | RE | 113 ms | 640 KB |
in2.txt | RE | 115 ms | 640 KB |
in20.txt | WA | 5 ms | 384 KB |
in3.txt | RE | 139 ms | 3708 KB |
in4.txt | AC | 1 ms | 256 KB |
in5.txt | RE | 108 ms | 256 KB |
in6.txt | RE | 106 ms | 256 KB |
in7.txt | RE | 108 ms | 384 KB |
in8.txt | RE | 111 ms | 640 KB |
in9.txt | AC | 1 ms | 256 KB |
long.txt | AC | 5 ms | 512 KB |
long2.txt | AC | 14 ms | 1532 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |