Submission #899074

# Submission time Handle Problem Language Result Execution time Memory
899074 2024-01-05T13:03:35 Z jamjanek Ancient Machine 2 (JOI23_ancient2) C++17
10 / 100
160 ms 1820 KB
#include "ancient2.h"
#include<bits/stdc++.h>
using namespace std;

bool prefix(int k){
	int m = k+1+2;
	vector<int>a(m), b(m);
	for(int i=0;i<k;i++){
		a[i] = i+1;
		b[i] = i+1;
	}
	a[k] = k+1;
	b[k] = k+2;
	a[k+2] = k+2;
	b[k+2] = k+2;
	a[k+1] = k+1;
	b[k+1] = k+1;
	return Query(m,a,b)==(k+2);
}

string PoznajSufix(int k){
	string s="2";
	while((int)s.size()-1<k){
		s[0]='0';
		s = '2' + s;
		int m = s.size();
		vector<int>a(m), b(m);
		vector<int>kmp(m);
		kmp[0] = 0;
		kmp[1] = 0;
//		printf("kmp sie liczy:\n");int pomin;scanf("%d", &pomin);
		for(int i=2;i<m;i++){
			int j = kmp[i-1];
			while(j!=0 && s[j+1]!=s[i])
				j = kmp[j];
			if(s[j+1]==s[i])
				j++;
			kmp[i] = j;
		}
//		printf("kmp sie policzylo\n");pomin;scanf("%d", &pomin);
		for(int i=0;i<m-1;i++){
			if(s[i+1]=='0'){
				a[i] = i+1;
				int j = kmp[i];
				while(s[j+1]!='1' && j!=0)j = kmp[j];
				if(s[j+1]=='1')j++;
				b[i] = j;
			}
			else if(s[i+1]=='1'){
				int j = kmp[i];
				while(s[j+1]!='0' && j!=0)j = kmp[j];
				if(s[j+1]=='0')j++;
				a[i] = j;
				b[i] = i+1;
			}
			//a[i]++;
			//b[i]++;
		}
//		printf("ostatniakra\n");
		int j = kmp[m-1];
		while(s[j+1]!='0' && j!=0)j = kmp[j];
		if(s[j+1]=='0')j++;
		a[m-1] = j;

		j = kmp[m-1];
		while(s[j+1]!='1' && j!=0)j = kmp[j];
		if(s[j+1]=='1')j++;
		b[m-1] = j;
/*
		cout<<s<<"\n";
		for(auto j: kmp)
			cout<<j<<" ";
		cout<<"\n";
		for(auto j: a)
			cout<<j<<" ";
		cout<<"\n";
		for(auto j: b)
			cout<<j<<" ";
		cout<<"\n";*/
		if(Query(m, a, b)!=m-1)
			s[1] = '1';
//		cout<<" "<<s<<"\n";
	}
	reverse(s.begin(), s.end());s.pop_back();reverse(s.begin(), s.end());
	return s;
}

string Solve(int N) {
	/*
	string s;
	while((int)s.size()<N){
		s.push_back('0'+prefix(s.size()));
	}*/
	string sufix;
	sufix = PoznajSufix(N);
//	cout<<sufix<<"\n";
	return sufix;
}
# Verdict Execution time Memory Grader output
1 Partially correct 85 ms 1084 KB Output is partially correct
2 Partially correct 82 ms 1676 KB Output is partially correct
3 Partially correct 81 ms 1400 KB Output is partially correct
4 Partially correct 82 ms 1168 KB Output is partially correct
5 Partially correct 81 ms 1428 KB Output is partially correct
6 Partially correct 92 ms 1356 KB Output is partially correct
7 Partially correct 85 ms 1096 KB Output is partially correct
8 Partially correct 123 ms 1324 KB Output is partially correct
9 Partially correct 91 ms 1092 KB Output is partially correct
10 Partially correct 121 ms 1428 KB Output is partially correct
11 Partially correct 119 ms 1492 KB Output is partially correct
12 Partially correct 79 ms 1272 KB Output is partially correct
13 Partially correct 76 ms 1004 KB Output is partially correct
14 Partially correct 77 ms 1520 KB Output is partially correct
15 Partially correct 85 ms 1464 KB Output is partially correct
16 Partially correct 160 ms 1584 KB Output is partially correct
17 Partially correct 157 ms 1468 KB Output is partially correct
18 Partially correct 79 ms 1148 KB Output is partially correct
19 Partially correct 78 ms 1364 KB Output is partially correct
20 Partially correct 95 ms 1308 KB Output is partially correct
21 Partially correct 78 ms 1560 KB Output is partially correct
22 Partially correct 79 ms 1072 KB Output is partially correct
23 Partially correct 84 ms 1584 KB Output is partially correct
24 Partially correct 82 ms 1348 KB Output is partially correct
25 Partially correct 82 ms 984 KB Output is partially correct
26 Partially correct 82 ms 1348 KB Output is partially correct
27 Partially correct 81 ms 1244 KB Output is partially correct
28 Partially correct 79 ms 1096 KB Output is partially correct
29 Partially correct 87 ms 1368 KB Output is partially correct
30 Partially correct 86 ms 1112 KB Output is partially correct
31 Partially correct 84 ms 1568 KB Output is partially correct
32 Partially correct 80 ms 1604 KB Output is partially correct
33 Partially correct 83 ms 1300 KB Output is partially correct
34 Partially correct 79 ms 1124 KB Output is partially correct
35 Partially correct 80 ms 1184 KB Output is partially correct
36 Partially correct 83 ms 1820 KB Output is partially correct
37 Partially correct 80 ms 992 KB Output is partially correct
38 Partially correct 86 ms 1356 KB Output is partially correct
39 Partially correct 85 ms 780 KB Output is partially correct
40 Partially correct 85 ms 1360 KB Output is partially correct
41 Partially correct 89 ms 1176 KB Output is partially correct
42 Partially correct 84 ms 1312 KB Output is partially correct
43 Partially correct 87 ms 1096 KB Output is partially correct
44 Partially correct 83 ms 1084 KB Output is partially correct
45 Partially correct 90 ms 1396 KB Output is partially correct
46 Partially correct 92 ms 1312 KB Output is partially correct
47 Partially correct 85 ms 1412 KB Output is partially correct
48 Partially correct 84 ms 924 KB Output is partially correct
49 Partially correct 91 ms 1468 KB Output is partially correct
50 Partially correct 84 ms 784 KB Output is partially correct
51 Partially correct 83 ms 1328 KB Output is partially correct
52 Partially correct 93 ms 1348 KB Output is partially correct
53 Partially correct 87 ms 1756 KB Output is partially correct
54 Partially correct 83 ms 1092 KB Output is partially correct
55 Partially correct 83 ms 1144 KB Output is partially correct
56 Partially correct 85 ms 1088 KB Output is partially correct
57 Partially correct 95 ms 1112 KB Output is partially correct
58 Partially correct 89 ms 1356 KB Output is partially correct
59 Partially correct 87 ms 1508 KB Output is partially correct
60 Partially correct 79 ms 1308 KB Output is partially correct
61 Partially correct 81 ms 1352 KB Output is partially correct
62 Partially correct 89 ms 1348 KB Output is partially correct
63 Partially correct 81 ms 1140 KB Output is partially correct