답안 #588942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
588942 2022-07-04T08:04:11 Z Arnch The Potion of Great Power (CEOI20_potion) C++17
17 / 100
3000 ms 4548 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 1e3 + 10, maxn = 1e6 + 10;

int n, d, h[maxn], a[maxn], b[maxn];
bool mark[maxn], mark2[maxn];

void init(int N, int D, int H[]) {
	n = N, d = D;
	for(int i = 0; i < n; i++) h[i] = H[i];
}

void curseChanges(int U, int A[], int B[]) {
	for(int i = 0; i < U; i++) a[i] = A[i], b[i] = B[i];
}

int question(int x, int y, int v) {
	for(int i = 0; i < v; i++) {
		mark[a[i]] = mark[b[i]] = 0;
		mark2[a[i]] = mark2[b[i]] = 0;
	}
	bool f = 0;
	set<int> stx, sty;
	for(int i = 0; i < v; i++) {	
		if(b[i] == x) swap(a[i], b[i]);
		if(a[i] == x) {
			if(mark[b[i]]) {
				stx.erase(b[i]);
				mark[b[i]] = 0;
			}
			else {
				mark[b[i]] = 1;
				stx.insert(b[i]);
			}
		}

		if(b[i] == y) swap(a[i], b[i]);
		if(a[i] == y) {
			if(mark2[b[i]]) {
				sty.erase(b[i]);
				mark2[b[i]] = 0;
			}
			else {
				mark2[b[i]] = 1;
				sty.insert(b[i]);
			}
			continue;
		}
	}

	int ans = 1e9;
	for(auto it : stx) 
		for(auto it2 : sty) {
			ans = min(ans, abs(h[it] - h[it2]));
		}

	return ans;

}

Compilation message

potion.cpp: In function 'int question(int, int, int)':
potion.cpp:23:7: warning: unused variable 'f' [-Wunused-variable]
   23 |  bool f = 0;
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 336 KB Output is correct
2 Correct 4 ms 336 KB Output is correct
3 Correct 5 ms 336 KB Output is correct
4 Correct 15 ms 1316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3026 ms 4548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3014 ms 4456 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1306 ms 592 KB Output is correct
2 Correct 1526 ms 484 KB Output is correct
3 Execution timed out 3070 ms 592 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 5 ms 336 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
4 Correct 5 ms 336 KB Output is correct
5 Correct 15 ms 1316 KB Output is correct
6 Execution timed out 3026 ms 4548 KB Time limit exceeded
7 Halted 0 ms 0 KB -