Submission #1178457


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);
    vector<string> av(K), sv(N-K);
    rep(K) cin >> an[i];
    int j = 0, k = 0;
    int min_length = 100000;
    rep(N){
        if(an[j] - 1 == i){
            cin >> av[j];
            if(min_length > (int)av[j].length()) min_length = (int)av[j].length();
            j++;
        }else{
            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 1623 Byte
Status RE
Exec Time 121 ms
Memory 5376 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 13
WA × 1
RE × 16
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 98 ms 384 KB
in10.txt RE 97 ms 384 KB
in11.txt RE 101 ms 896 KB
in12.txt RE 96 ms 256 KB
in13.txt RE 98 ms 384 KB
in14.txt RE 98 ms 384 KB
in15.txt WA 3 ms 384 KB
in16.txt AC 1 ms 256 KB
in17.txt RE 98 ms 384 KB
in18.txt RE 99 ms 256 KB
in19.txt RE 102 ms 896 KB
in2.txt RE 102 ms 896 KB
in20.txt RE 100 ms 512 KB
in3.txt RE 121 ms 5376 KB
in4.txt AC 1 ms 256 KB
in5.txt RE 96 ms 256 KB
in6.txt RE 96 ms 256 KB
in7.txt RE 98 ms 384 KB
in8.txt RE 100 ms 896 KB
in9.txt AC 1 ms 256 KB
long.txt AC 4 ms 512 KB
long2.txt AC 12 ms 2176 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB