답안 #760170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
760170 2023-06-17T08:54:36 Z jk410 On the Grid (FXCUP4_grid) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
#include "grid.h"
using namespace std;

bool used[1001];
bool usedIdx[1000];

int myQuery(vector<int>& v1, vector<int>& v2,int k) {
	vector<int> v;
	for (int i = (int)v1.size() - k; i < (int)v1.size(); i++)
		v.push_back(v1[i]);
	for (int i = 0; i < (int)v1.size() - k; i++)
		v.push_back(v1[i]);
	for (int i : v2)
		v.push_back(i);
	return PutDisks(v);
}

std::vector<int> SortDisks(int N) {
	vector<int> ret(N);
	vector<int> revret(N+1);
	fill(revret.begin(), revret.end(), -1);
	for (int i = 1; i < N; i++) {
		vector<int> v, v2;
		for (int j = 0; j < N; j++) {
			if (!usedIdx[j])
				v.push_back(j);
		}
		for (int j = 1; j <= N; j++) {
			if (revret[j] != -1)
				v2.push_back(revret[j]);
		}
		int cur = myQuery(v, v2, 0);
		int l = 1, r = (int)v.size() - 1, x, y;
		while (l <= r) {
			int m = (l + r) >> 1;
			int tmp = myQuery(v, v2, m);
			if (tmp > cur) {
				x = m;
				y = tmp;
				r = m - 1;
			}
			else
				l = m + 1;
		}
		ret[v[(int)v.size() - x]] = y - N + 1;
		revret[y - N + 1] = v[(int)v.size() - x];
		used[y - N + 1] = true;
		usedIdx[v[(int)v.size() - x]] = true;
	}
	int x, y;
	for (int i = 0; i < N; i++) {
		if (!usedIdx[i])
			x = i;
	}
	for (int i = 1; i <= N; i++) {
		if (!used[i])
			y = i;
	}
	ret[x] = y;
	return ret;
}

Compilation message

grid.cpp: In function 'std::vector<int> SortDisks(int)':
grid.cpp:60:7: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |  ret[x] = y;
      |       ^
grid.cpp:60:9: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |  ret[x] = y;
grid.cpp:46:33: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |   ret[v[(int)v.size() - x]] = y - N + 1;
      |                               ~~^~~
grid.cpp:46:23: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |   ret[v[(int)v.size() - x]] = y - N + 1;
      |         ~~~~~~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -