Submission #821371

# Submission time Handle Problem Language Result Execution time Memory
821371 2023-08-11T09:37:07 Z ono_de206 Ancient Machine 2 (JOI23_ancient2) C++17
37 / 100
55 ms 476 KB
#include "ancient2.h"
#include<bits/stdc++.h>
using namespace std;

#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second

//#define int long long

typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int ask(vector<int> a, vector<int> b) {
	return Query((int)a.size(), a, b);
}

string Solve(int n) {
	vector<int> a, b;
	int l = 0;
	string ans = "";
	auto getNext = [&]() -> char {
		int m = (int)a.size();
		a.pb(m + 2);
		b.pb(m + 1);
		for(int i = 0; i < 2; i++) {
			a.pb(m + i + 1);
			b.pb(m + i + 1);
		}
		int ret = ask(a, b);
		for(int i = 0; i < 3; i++) {
			a.pop_back();
			b.pop_back();
		}
		return (ret == m + 2 ? '0' : '1');
	};
	auto push = [&](char ch) -> void {
		int m = (int)a.size();
		if(ch == '0') {
			a.pb(m);
			b.pb(m + 1);
		} else {
			a.pb(m + 1);
			b.pb(m);
		}
	};
	while(l < n) {
		char nxt = getNext();
		ans.pb(nxt);
		l++;
		if(l == n) break;
		int ls = (int)a.size();
		bool found = 0;
		a.pb((int)a.size() + 1);
		b.pb((int)b.size() + 1);
		while(a.size() <= 500 && l < n) {
			char ch = getNext();
			ans.pb(ch);
			l++;
			if(ch != nxt) {
				found = 1;
				break;
			}
			a.pb((int)a.size() + 1);
			b.pb((int)b.size() + 1);
		}
		if(l == n) break;
		while(a.size() > ls) {
			a.pop_back();
			b.pop_back();
		}
		push(nxt);
		if(found) {
			continue;
		}
		int m = a.size();
		while(a.size() < 504) {
			a.pb((int)a.size());
			b.pb((int)b.size());
		}
		a.pb(504);
		b.pb(504);
		int len = ask(a, b) - m;
		int nxtl = n - len;
		while(ans.size() < nxtl - 1) {
			ans.pb(nxt);
		}
		ans.pb(nxt ^ '0' ^ '1');
		while(a.size() > m) {
			a.pop_back();
			b.pop_back();
		}
		l = nxtl;
	}
	return ans;
}

Compilation message

ancient2.cpp: In function 'std::string Solve(int)':
ancient2.cpp:75:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   75 |   while(a.size() > ls) {
      |         ~~~~~~~~~^~~~
ancient2.cpp:92:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   92 |   while(ans.size() < nxtl - 1) {
      |         ~~~~~~~~~~~^~~~~~~~~~
ancient2.cpp:96:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   96 |   while(a.size() > m) {
      |         ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Partially correct 18 ms 372 KB Output is partially correct
2 Partially correct 22 ms 356 KB Output is partially correct
3 Partially correct 27 ms 348 KB Output is partially correct
4 Partially correct 34 ms 400 KB Output is partially correct
5 Partially correct 23 ms 408 KB Output is partially correct
6 Partially correct 32 ms 380 KB Output is partially correct
7 Partially correct 46 ms 424 KB Output is partially correct
8 Partially correct 55 ms 428 KB Output is partially correct
9 Partially correct 33 ms 400 KB Output is partially correct
10 Partially correct 43 ms 428 KB Output is partially correct
11 Partially correct 42 ms 436 KB Output is partially correct
12 Correct 18 ms 300 KB Output is correct
13 Partially correct 19 ms 308 KB Output is partially correct
14 Correct 17 ms 316 KB Output is correct
15 Partially correct 15 ms 316 KB Output is partially correct
16 Partially correct 36 ms 432 KB Output is partially correct
17 Partially correct 46 ms 424 KB Output is partially correct
18 Partially correct 39 ms 436 KB Output is partially correct
19 Partially correct 44 ms 364 KB Output is partially correct
20 Partially correct 43 ms 428 KB Output is partially correct
21 Partially correct 45 ms 444 KB Output is partially correct
22 Partially correct 22 ms 380 KB Output is partially correct
23 Partially correct 24 ms 364 KB Output is partially correct
24 Partially correct 28 ms 364 KB Output is partially correct
25 Partially correct 31 ms 308 KB Output is partially correct
26 Partially correct 20 ms 468 KB Output is partially correct
27 Partially correct 24 ms 376 KB Output is partially correct
28 Partially correct 22 ms 328 KB Output is partially correct
29 Partially correct 21 ms 348 KB Output is partially correct
30 Partially correct 22 ms 348 KB Output is partially correct
31 Partially correct 15 ms 312 KB Output is partially correct
32 Correct 15 ms 300 KB Output is correct
33 Correct 15 ms 208 KB Output is correct
34 Correct 15 ms 304 KB Output is correct
35 Partially correct 19 ms 304 KB Output is partially correct
36 Correct 21 ms 300 KB Output is correct
37 Partially correct 22 ms 340 KB Output is partially correct
38 Partially correct 28 ms 432 KB Output is partially correct
39 Partially correct 36 ms 344 KB Output is partially correct
40 Partially correct 28 ms 360 KB Output is partially correct
41 Partially correct 28 ms 428 KB Output is partially correct
42 Partially correct 30 ms 324 KB Output is partially correct
43 Partially correct 28 ms 396 KB Output is partially correct
44 Partially correct 30 ms 364 KB Output is partially correct
45 Partially correct 30 ms 388 KB Output is partially correct
46 Partially correct 28 ms 368 KB Output is partially correct
47 Partially correct 40 ms 476 KB Output is partially correct
48 Partially correct 29 ms 428 KB Output is partially correct
49 Partially correct 35 ms 432 KB Output is partially correct
50 Partially correct 30 ms 328 KB Output is partially correct
51 Partially correct 30 ms 428 KB Output is partially correct
52 Partially correct 38 ms 416 KB Output is partially correct
53 Partially correct 31 ms 412 KB Output is partially correct
54 Partially correct 34 ms 336 KB Output is partially correct
55 Partially correct 32 ms 356 KB Output is partially correct
56 Partially correct 37 ms 428 KB Output is partially correct
57 Correct 19 ms 208 KB Output is correct
58 Partially correct 25 ms 308 KB Output is partially correct
59 Partially correct 15 ms 320 KB Output is partially correct
60 Partially correct 16 ms 308 KB Output is partially correct
61 Partially correct 26 ms 304 KB Output is partially correct
62 Partially correct 29 ms 432 KB Output is partially correct
63 Partially correct 36 ms 336 KB Output is partially correct