Submission #1179556


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[i].length()){
				min_length = (int)av[i].length();
			}
            if(j < K) j++;
        }else{
			sv.push_back(tmp);
            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 1684 Byte
Status RE
Exec Time 107 ms
Memory 2300 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 13
WA × 2
RE × 15
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 101 ms 384 KB
in10.txt RE 98 ms 256 KB
in11.txt RE 98 ms 256 KB
in12.txt RE 99 ms 384 KB
in13.txt WA 4 ms 384 KB
in14.txt RE 98 ms 256 KB
in15.txt WA 3 ms 384 KB
in16.txt AC 1 ms 256 KB
in17.txt RE 101 ms 384 KB
in18.txt RE 100 ms 384 KB
in19.txt RE 103 ms 768 KB
in2.txt RE 98 ms 256 KB
in20.txt RE 107 ms 512 KB
in3.txt RE 107 ms 1408 KB
in4.txt AC 1 ms 256 KB
in5.txt RE 100 ms 256 KB
in6.txt RE 98 ms 256 KB
in7.txt RE 100 ms 384 KB
in8.txt RE 101 ms 512 KB
in9.txt AC 1 ms 256 KB
long.txt AC 4 ms 512 KB
long2.txt AC 13 ms 2300 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB