Submission #1680385
Source Code Expand
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
// #define DEBUG
#ifdef DEBUG
#define dump(...) fprintf(stderr, __VA_ARGS__)
#else
#define dump(...)
#endif
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);
int main(void){
cin.tie(0);
ios::sync_with_stdio(false);
int n, K; cin >> n >> K;
if(n == K){
cout << endl;
return 0;
}
vi a(K); for(auto& e : a) cin >> e, e--;
set<int> s(_all(a));
vector<string> in(n); for(auto& e : in) cin >> e;
int ri = a[0];
for(auto& i : a){
if(in[i].size() > in[ri].size()){
ri = i;
}
}
vi ord(n);
{
using Elem = tuple<int, int>;
vector<Elem> tbl(n);
rep(i, n) tbl[i] = Elem((int)in[i].size(), i);
sort(_all(tbl), greater<Elem>());
rep(i, n) ord[i] = get<1>(tbl[i]);
}
int res = -1;
rep(l, 1, (int)1e5 + 5){
int cnt = 0;
bool other = false;
if((int)in[ri].size() < l) break;
char c = in[ri][l - 1];
rep(_, n){
int i = ord[_];
if((int)in[i].size() < l) break;
if(in[i][l - 1] == c){
if(s.find(i) != end(s)) cnt++;
else {
other = true;
break;
}
}
}
if(not other and cnt == (int)s.size()){
res = l;
break;
}
}
if(res == -1){
cout << res << endl;
}
else {
cout << in[ri].substr(0, res) << endl;
}
return 0;
}
Submission Info
Submission Time |
|
Task |
C - 検索 |
User |
nokoTaro |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3168 Byte |
Status |
WA |
Exec Time |
25 ms |
Memory |
7424 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 |
AC |
2 ms |
384 KB |
in10.txt |
WA |
2 ms |
384 KB |
in11.txt |
WA |
4 ms |
1024 KB |
in12.txt |
AC |
1 ms |
384 KB |
in13.txt |
WA |
2 ms |
512 KB |
in14.txt |
WA |
2 ms |
384 KB |
in15.txt |
AC |
1 ms |
384 KB |
in16.txt |
AC |
1 ms |
256 KB |
in17.txt |
WA |
2 ms |
384 KB |
in18.txt |
AC |
4 ms |
512 KB |
in19.txt |
AC |
4 ms |
896 KB |
in2.txt |
AC |
4 ms |
1024 KB |
in20.txt |
AC |
2 ms |
512 KB |
in3.txt |
AC |
25 ms |
7424 KB |
in4.txt |
AC |
1 ms |
256 KB |
in5.txt |
AC |
1 ms |
384 KB |
in6.txt |
AC |
1 ms |
256 KB |
in7.txt |
WA |
1 ms |
384 KB |
in8.txt |
WA |
4 ms |
1024 KB |
in9.txt |
AC |
1 ms |
256 KB |
long.txt |
AC |
2 ms |
512 KB |
long2.txt |
AC |
12 ms |
2560 KB |
sample1.txt |
AC |
1 ms |
256 KB |
sample2.txt |
AC |
1 ms |
256 KB |
sample3.txt |
AC |
1 ms |
256 KB |