Submission #423759

# Submission time Handle Problem Language Result Execution time Memory
423759 2021-06-11T12:23:49 Z patrikpavic2 Monster Game (JOI21_monster) C++17
100 / 100
157 ms 272 KB
#include "monster.h"
#include <vector>
#include <cstdio>
#include <ctime>
#include <algorithm>
#include <unistd.h>
 
#define PB push_back
 
using namespace std;
 
typedef vector < int > vi;
 
namespace {
 
bool example_variable;
 
void merge_sort(vi &v){
	if((int)v.size() <= 1) return;
	vi A[2];
	for(int i = 0;i < (int)v.size();i++)
		A[i & 1].PB(v[i]);
	merge_sort(A[0]); merge_sort(A[1]);
	v.clear();
	int i = 0, j = 0;
	for(;i < (int)A[0].size() || j < (int)A[1].size();){
		if(i == (int)A[0].size()) v.PB(A[1][j++]);
		else if(j == (int)A[1].size()) v.PB(A[0][i++]); 
		else if(!Query(A[0][i], A[1][j])) v.PB(A[0][i++]);
		else v.PB(A[1][j++]);
	}
}
 
}  // namespace
 
vi Solve(int n) {
	vi v, ret(n); 
	for(int i = 0;i < n;i++)
		v.PB(i);
	random_shuffle(v.begin(), v.end());
	merge_sort(v); 
	int pref = 0, cnt = 0;
	for(int i = 1;i < n && i < 100;i++)
		cnt += Query(v[0], v[i]);
	if(cnt == 1){
		int cnt2 = 0;
		for(int i = 2;i < n && i < 100;i++)
			cnt2 += Query(v[1], v[i]);
		if(cnt2 == 0)
			pref = 1;
		else
			pref = 0;
	}
	else
		pref = cnt;
	int lst = pref;
	reverse(v.begin(), v.begin() + pref + 1);
	for(int i = lst + 1;i < n;i++){
		while(i < (int)v.size() && !Query(v[lst], v[i]))
			i++;
		reverse(v.begin() + lst + 1, v.begin() + i + 1);
		lst = i;
	}	
	for(int i = 0;i < n;i++)
		ret[v[i]] = i;
	return ret;
}

Compilation message

monster.cpp:16:6: warning: '{anonymous}::example_variable' defined but not used [-Wunused-variable]
   16 | bool example_variable;
      |      ^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 272 KB Output is correct
16 Correct 23 ms 200 KB Output is correct
17 Correct 21 ms 200 KB Output is correct
18 Correct 20 ms 200 KB Output is correct
19 Correct 19 ms 200 KB Output is correct
20 Correct 8 ms 200 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 17 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 18 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 0 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 272 KB Output is correct
16 Correct 23 ms 200 KB Output is correct
17 Correct 21 ms 200 KB Output is correct
18 Correct 20 ms 200 KB Output is correct
19 Correct 19 ms 200 KB Output is correct
20 Correct 8 ms 200 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 17 ms 200 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 18 ms 200 KB Output is correct
33 Correct 105 ms 200 KB Output is correct
34 Correct 104 ms 200 KB Output is correct
35 Correct 120 ms 268 KB Output is correct
36 Correct 95 ms 200 KB Output is correct
37 Correct 112 ms 200 KB Output is correct
38 Correct 48 ms 200 KB Output is correct
39 Correct 82 ms 200 KB Output is correct
40 Correct 157 ms 200 KB Output is correct
41 Correct 99 ms 200 KB Output is correct
42 Correct 126 ms 200 KB Output is correct
43 Correct 81 ms 200 KB Output is correct
44 Correct 113 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 200 KB Output is correct
2 Correct 112 ms 256 KB Output is correct
3 Correct 150 ms 200 KB Output is correct
4 Correct 155 ms 200 KB Output is correct
5 Correct 80 ms 200 KB Output is correct
6 Correct 128 ms 200 KB Output is correct
7 Correct 75 ms 200 KB Output is correct
8 Correct 90 ms 200 KB Output is correct
9 Correct 77 ms 272 KB Output is correct
10 Correct 120 ms 268 KB Output is correct
11 Correct 85 ms 256 KB Output is correct
12 Correct 107 ms 200 KB Output is correct
13 Correct 73 ms 200 KB Output is correct
14 Correct 100 ms 200 KB Output is correct
15 Correct 58 ms 200 KB Output is correct
16 Correct 71 ms 200 KB Output is correct
17 Correct 110 ms 200 KB Output is correct
18 Correct 56 ms 200 KB Output is correct