답안 #40035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
40035 2018-01-25T14:09:50 Z cheater2k Memory 2 (JOI16_memory2) C++14
100 / 100
0 ms 2024 KB
#include "Memory2_lib.h"
#include <bits/stdc++.h>
using namespace std;

static const int MAX = 50;
static vector<int> pos[MAX];

void Solve(int T, int N){
	srand(time(NULL));
	vector<int> rem;
	for (int i = 0; i < 2 * N; ++i) rem.push_back(i);

	while(rem.size()) {
		// reset
		for (int i = 0; i < MAX; ++i) pos[i].clear();

		// ask
		int pivot = rem[rand() % rem.size()];

		for (int p : rem) if (p != pivot) {
			int reply = Flip(p, pivot);
			pos[reply].push_back(p);
		}

		int cur;
		for (int i = 0; i < MAX; ++i) {
			if (pos[i].size() == 2) {
				Answer(min(pos[i][0], pos[i][1]), max(pos[i][0], pos[i][1]), i);
				rem.erase(find(rem.begin(), rem.end(), pos[i][0]));
				rem.erase(find(rem.begin(), rem.end(), pos[i][1]));
			} else if (pos[i].size() & 1) {
				cur = i;
			}
		}

		if (rem.size() == 2) { // only 2 cards remain
			Answer(min(rem[0], rem[1]), max(rem[0], rem[1]), cur);
			break;
		}
	}		
}

Compilation message

memory2.cpp: In function 'void Solve(int, int)':
memory2.cpp:37:57: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
    Answer(min(rem[0], rem[1]), max(rem[0], rem[1]), cur);
                                                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
3 Correct 0 ms 2024 KB Output is correct
4 Correct 0 ms 2024 KB Output is correct
5 Correct 0 ms 2024 KB Output is correct
6 Correct 0 ms 2024 KB Output is correct
7 Correct 0 ms 2024 KB Output is correct
8 Correct 0 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
3 Correct 0 ms 2024 KB Output is correct
4 Correct 0 ms 2024 KB Output is correct
5 Correct 0 ms 2024 KB Output is correct
6 Correct 0 ms 2024 KB Output is correct
7 Correct 0 ms 2024 KB Output is correct
8 Correct 0 ms 2024 KB Output is correct
9 Correct 0 ms 2024 KB Output is correct
10 Correct 0 ms 2024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
3 Correct 0 ms 2024 KB Output is correct
4 Correct 0 ms 2024 KB Output is correct
5 Correct 0 ms 2024 KB Output is correct
6 Correct 0 ms 2024 KB Output is correct
7 Correct 0 ms 2024 KB Output is correct
8 Correct 0 ms 2024 KB Output is correct
9 Correct 0 ms 2024 KB Output is correct
10 Correct 0 ms 2024 KB Output is correct