Submission #1680176
Source Code Expand
#include <bits/stdc++.h> #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() #define LL long long #define pii pair<int,int> #define pll pair<LL,LL> using namespace std; int main(){ int N,K;cin>>N>>K; vector<string> S; set<int> A; vector<string> s; REP(i,K){ int a;cin>>a; A.insert(--a); } REP(i,N){ string _s;cin>>_s; S.push_back(_s); if(A.count(i))s.push_back(_s); } sort(ALL(s)); sort(ALL(S)); if(upper_bound(ALL(S),s[K-1]) - lower_bound(ALL(S),s[0]) !=K){ cout<<-1<<endl; return 0; } string ans=""; int index = 0; while(upper_bound(ALL(S),ans +(char)('z'+1))!=upper_bound(ALL(S),s[K-1]) || lower_bound(ALL(S),ans)!=lower_bound(ALL(S),s[0])){ if(index>=s[0].size()){ cout<<-1<<endl; return 0; } ans += s[0][index++]; } cout<<ans<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - 検索 |
User | inmir |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 1023 Byte |
Status | AC |
Exec Time | 627 ms |
Memory | 11240 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 | 5 ms | 384 KB |
in10.txt | AC | 4 ms | 384 KB |
in11.txt | AC | 10 ms | 896 KB |
in12.txt | AC | 5 ms | 384 KB |
in13.txt | AC | 5 ms | 512 KB |
in14.txt | AC | 5 ms | 384 KB |
in15.txt | AC | 7 ms | 384 KB |
in16.txt | AC | 1 ms | 256 KB |
in17.txt | AC | 5 ms | 384 KB |
in18.txt | AC | 5 ms | 512 KB |
in19.txt | AC | 11 ms | 896 KB |
in2.txt | AC | 12 ms | 896 KB |
in20.txt | AC | 5 ms | 512 KB |
in3.txt | AC | 62 ms | 6260 KB |
in4.txt | AC | 133 ms | 11240 KB |
in5.txt | AC | 5 ms | 384 KB |
in6.txt | AC | 2 ms | 256 KB |
in7.txt | AC | 4 ms | 384 KB |
in8.txt | AC | 9 ms | 896 KB |
in9.txt | AC | 133 ms | 11240 KB |
long.txt | AC | 627 ms | 640 KB |
long2.txt | AC | 302 ms | 2300 KB |
sample1.txt | AC | 1 ms | 256 KB |
sample2.txt | AC | 1 ms | 256 KB |
sample3.txt | AC | 1 ms | 256 KB |