Submission #576465


Source Code Expand

Copy
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<iterator>
#include<stack>
#include<utility>

#define rep(i,n) for(int i = 0; i != n; i++)

using namespace std;



int main(){
	int N,K;
	cin >> K >> N;
	vector<string> res(K, "FAIL");
	vector<string> a;
	vector<string> b;

	rep(i,N){
		string temp1,temp2;
		cin >> temp1 >> temp2;
		a.push_back(temp1);
		b.push_back(temp2);
	}
	long i = 0;
	rep(i, pow(3, K)){
		vector<string> nowres(K, "FAIL");
		vector<int> keta(K, 0);
		long wari = i;
		rep(j,K){
			keta[j] = wari % 3 + 1;
			wari /= 3;
		}
		int check = 0;
		rep(j,N){
			int k = 0;
			bool flag = 0;
			rep(iter, a[j].length()){
				if(k >= b[j].length()){
					flag = 1;
					break;
				}
				int now = a[j][iter] - '0' - 1;
				if(nowres[now].compare( "FAIL") == 0){
					string temp;
					rep(l, keta[now]){
						if(k < b[j].length()){
						temp.push_back(b[j][k]);
						k++;	
						}
					}
					if(temp.length() != keta[now]){flag = 1; break;}
					nowres[now] = temp;
				}
				else{
					bool flag_ = 0;
					rep(l, keta[now]){
						if(b[j][k] - nowres[now][l] != 0) flag_ = 1;
						k++;
					}
					if(flag_){flag = 1; break;}
				}
			}
			if(flag || k != b[j].length()){ check = 1; break;}
		}
		if(check == 0){
		res = nowres;
		break;
		}
	}
	rep(i,K){
	cout << res[i] << endl;
	}
}

Submission Info

Submission Time
Task D - 語呂合わせ
User dolicas
Language C++11 (GCC 4.9.2)
Score 100
Code Size 1449 Byte
Status AC
Exec Time 65 ms
Memory 928 KB

Judge Result

Set Name Sample Subtask1 Subtask2
Score / Max Score 0 / 0 40 / 40 60 / 60
Status
AC × 4
AC × 23
AC × 44
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Subtask1 sample-02.txt, sample-03.txt, sample-04.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt
Subtask2 sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt, subtask1-17.txt, subtask1-18.txt, subtask1-19.txt, subtask1-20.txt, subtask2-01.txt, subtask2-02.txt, subtask2-03.txt, subtask2-04.txt, subtask2-05.txt, subtask2-06.txt, subtask2-07.txt, subtask2-08.txt, subtask2-09.txt, subtask2-10.txt, subtask2-11.txt, subtask2-12.txt, subtask2-13.txt, subtask2-14.txt, subtask2-15.txt, subtask2-16.txt, subtask2-17.txt, subtask2-18.txt, subtask2-19.txt, subtask2-20.txt
Case Name Status Exec Time Memory
sample-01.txt AC 26 ms 920 KB
sample-02.txt AC 27 ms 800 KB
sample-03.txt AC 26 ms 920 KB
sample-04.txt AC 26 ms 808 KB
subtask1-01.txt AC 26 ms 924 KB
subtask1-02.txt AC 26 ms 804 KB
subtask1-03.txt AC 27 ms 800 KB
subtask1-04.txt AC 25 ms 804 KB
subtask1-05.txt AC 26 ms 800 KB
subtask1-06.txt AC 26 ms 808 KB
subtask1-07.txt AC 25 ms 920 KB
subtask1-08.txt AC 24 ms 924 KB
subtask1-09.txt AC 26 ms 804 KB
subtask1-10.txt AC 26 ms 928 KB
subtask1-11.txt AC 26 ms 924 KB
subtask1-12.txt AC 26 ms 800 KB
subtask1-13.txt AC 25 ms 924 KB
subtask1-14.txt AC 27 ms 800 KB
subtask1-15.txt AC 26 ms 808 KB
subtask1-16.txt AC 25 ms 796 KB
subtask1-17.txt AC 27 ms 796 KB
subtask1-18.txt AC 26 ms 916 KB
subtask1-19.txt AC 27 ms 920 KB
subtask1-20.txt AC 26 ms 796 KB
subtask2-01.txt AC 35 ms 804 KB
subtask2-02.txt AC 33 ms 740 KB
subtask2-03.txt AC 42 ms 924 KB
subtask2-04.txt AC 51 ms 920 KB
subtask2-05.txt AC 54 ms 928 KB
subtask2-06.txt AC 35 ms 792 KB
subtask2-07.txt AC 64 ms 920 KB
subtask2-08.txt AC 29 ms 796 KB
subtask2-09.txt AC 65 ms 796 KB
subtask2-10.txt AC 57 ms 800 KB
subtask2-11.txt AC 54 ms 920 KB
subtask2-12.txt AC 39 ms 916 KB
subtask2-13.txt AC 49 ms 800 KB
subtask2-14.txt AC 48 ms 928 KB
subtask2-15.txt AC 41 ms 808 KB
subtask2-16.txt AC 30 ms 800 KB
subtask2-17.txt AC 27 ms 812 KB
subtask2-18.txt AC 55 ms 916 KB
subtask2-19.txt AC 49 ms 804 KB
subtask2-20.txt AC 52 ms 804 KB