Submission #1081367

# Submission time Handle Problem Language Result Execution time Memory
1081367 2024-08-30T02:06:08 Z kes0716 Archery (IOI09_archery) C++17
52 / 100
258 ms 7508 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200009;
int n, r, crit;
int a[2*MAXN];
struct State{
	int pl, ze, mi;
	State operator+(const State &s) const{
		return (State){pl+s.pl, ze+s.ze, mi+s.mi};
	}
} init[MAXN];
int simulate1(void){
	assert(0);
	vector<State> pot(3*n);
	State pq = {0, 0, 0};
	int i, j;
	for(i=0; i<n; i++){
		pot[i] = init[i];
	}
	int cnt = 0, last = -1;
	for(i=0; i<3*n; i++){
		pq = pq + pot[i];
		//printf("i=%d pq= +%d 0%d -%d\n", i, pq.pl, pq.ze, pq.mi);
		assert(pq.pl + pq.ze + pq.mi >= 2);
		if(pq.pl < 2 && pq.ze)
			last = i;
		if(pq.pl >= 2){
			if(i < 2*n)
				pot[i+n].pl++;
			pq.pl--;
		}
		else if(pq.pl == 1){
			if(pq.ze){
				if(i < 2*n)
					pot[i+n].ze++;
				pq.ze--;
				cnt++;
			}
			else{
				if(i < 2*n)
					pot[i+n].mi++;
				pq.mi--;
			}
		}
		else{
			if(i < 2*n)
				pot[i+n].mi++;
			pq.mi--;
		}
	}
	//printf("last=%d cnt=%d\n", last, cnt);
	int ret = last - r - n*cnt;
	if(ret%n == 0)
		ret += n;
	return ret;
}
int simulate2(int pos){
	State pq = {0, 0, 0};
	int i, ans = pos;
	for(i=2*n; i>=1; i--){
		int cur = i%n;
		pq = pq + init[cur];
		//printf("i=%d pq.pl=%d ze=%d mi=%d\n", i,pq.pl, pq.ze, pq.mi);
		init[cur].pl = init[cur].mi = init[cur].ze = 0;
		if(cur){
			if(pq.mi){
				if(pq.ze)
					ans--;
				init[cur].mi = 1;
				pq.mi--;
			}
			else if(pq.ze){
				init[cur].ze = 1;
				pq.ze--;
			}
		}
		else{
			if(pq.ze)
				ans--;
		}
	}
	return ans;
}
int simulate(int p){
	int i, j=0;
	for(i=0; i<n; i++){
		init[i].pl = init[i].ze = init[i].mi = 0;
		if(p == i)
			init[i].ze++;
		else{
			if(a[j] < crit)
				init[i].pl++;
			else
				init[i].mi++;
			j++;
		}
		if(a[j] < crit)
			init[i].pl++;
		else
			init[i].mi++;
		j++;
	}
	if(crit <= n+1)
		return simulate1();
	return simulate2(p);
}
int main(){
	int i;
	scanf("%d %d", &n, &r);
	r = 2*n + r%n;
	scanf("%d", &crit);
	for(i=0; i<2*n-1; i++){
		scanf("%d", &a[i]);
	}
	if(crit==1){
		printf("%d\n", n);
		return 0;
	}
	pair<int, int> ans = make_pair(n, -1);	//(result, -start)
	for(int t=-3; t<=0; t++){
		int goal = t*n, lo = 0, hi = n-1, mid;
		while(lo < hi){
			mid = (lo+hi)/2;
			if(simulate(mid) >= goal)
				hi = mid;
			else
				lo = mid+1;
		}
		int crit = simulate(lo);
		//printf("lo=%d crit=%d\n", lo, crit);
		hi = n-1;
		while(lo < hi){
			mid = (lo+hi+1)/2;
			if(simulate(mid) == crit)
				lo = mid;
			else
				hi = mid-1;
		}
		//printf("lo=%d\n", lo);
		ans = min(ans, make_pair((crit%n + n)%n, -lo-1));
	}
	printf("%d\n", -ans.second);
	return 0;
}

Compilation message

archery.cpp: In function 'int simulate1()':
archery.cpp:16:9: warning: unused variable 'j' [-Wunused-variable]
   16 |  int i, j;
      |         ^
archery.cpp: In function 'int main()':
archery.cpp:109:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |  scanf("%d %d", &n, &r);
      |  ~~~~~^~~~~~~~~~~~~~~~~
archery.cpp:111:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |  scanf("%d", &crit);
      |  ~~~~~^~~~~~~~~~~~~
archery.cpp:113:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |   scanf("%d", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Runtime error 1 ms 604 KB Execution killed with signal 6
4 Runtime error 2 ms 604 KB Execution killed with signal 6
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Runtime error 1 ms 604 KB Execution killed with signal 6
3 Runtime error 1 ms 604 KB Execution killed with signal 6
4 Runtime error 3 ms 1116 KB Execution killed with signal 6
5 Runtime error 28 ms 7124 KB Execution killed with signal 6
6 Runtime error 1 ms 604 KB Execution killed with signal 6
7 Runtime error 1 ms 604 KB Execution killed with signal 6
8 Runtime error 3 ms 1116 KB Execution killed with signal 6
9 Runtime error 4 ms 1372 KB Execution killed with signal 6
10 Runtime error 1 ms 604 KB Execution killed with signal 6
11 Runtime error 4 ms 1372 KB Execution killed with signal 6
12 Runtime error 1 ms 604 KB Execution killed with signal 6
13 Runtime error 19 ms 5364 KB Execution killed with signal 6
14 Runtime error 1 ms 604 KB Execution killed with signal 6
15 Runtime error 5 ms 1884 KB Execution killed with signal 6
16 Runtime error 1 ms 604 KB Execution killed with signal 6
17 Runtime error 1 ms 604 KB Execution killed with signal 6
18 Runtime error 1 ms 600 KB Execution killed with signal 6
19 Runtime error 1 ms 604 KB Execution killed with signal 6
20 Runtime error 1 ms 604 KB Execution killed with signal 6
21 Runtime error 4 ms 1348 KB Execution killed with signal 6
22 Runtime error 5 ms 1604 KB Execution killed with signal 6
23 Runtime error 39 ms 7508 KB Execution killed with signal 6
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 5 ms 552 KB Output is correct
27 Correct 30 ms 860 KB Output is correct
28 Correct 258 ms 2908 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 4 ms 544 KB Output is correct
31 Correct 17 ms 600 KB Output is correct
32 Correct 188 ms 3672 KB Output is correct
33 Correct 1 ms 600 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 2 ms 344 KB Output is correct
37 Correct 14 ms 604 KB Output is correct
38 Correct 22 ms 932 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 2 ms 344 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 5 ms 348 KB Output is correct
44 Correct 8 ms 600 KB Output is correct
45 Correct 16 ms 840 KB Output is correct
46 Correct 19 ms 860 KB Output is correct
47 Correct 189 ms 4188 KB Output is correct