답안 #510048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
510048 2022-01-14T15:01:38 Z Elegia The Collection Game (BOI21_swaps) C++17
0 / 100
1 ms 200 KB
//
// --- Sample implementation for the task swaps ---
//
// To compile this program with the sample grader, place:
//     swaps.h swaps_sample.cpp sample_grader.cpp
// in a single folder and run:
//     g++ swaps_sample.cpp sample_grader.cpp
// in this folder.
//
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>
#include <numeric>
#include "swaps.h"

using namespace std;

void solve(int N, int V) {
	vector<vector<int>> ord;
	for (int i = 1; i <= N; ++i) ord.push_back({i});
	for (int rep = 1; ord.size() > 1; ++rep) {
		vector<vector<int>> low(ord.size()), high(ord.size());
		for (int i = 1; i < ord.size(); i += 2) {
			low[i].assign(ord[i].size(), 0);
			high[i].assign(ord[i].size(), ord[i - 1].size());
		}
		for (int per = 0; per != rep; ++per) {
			for (int i = 1; i < ord.size(); i += 2)
				for (int j = 0; j != ord[i].size(); ++j) {
					int mid = (low[i][j] + high[i][j]) / 2;
					schedule(ord[i - 1][mid], ord[i][j]);
				}
			vector<int> res = visit(); int cnt = 0;
			for (int i = 1; i < ord.size(); i += 2)
				for (int j = 0; j != ord[i].size(); ++j) {
					int mid = (low[i][j] + high[i][j]) / 2;
					if (res[cnt++]) low[i][j] = mid + 1;
					else high[i][j] = mid;
				}
		}
		vector<vector<int>> tmp;
		for (int i = 1; i < ord.size(); i += 2) {
			vector<int> nw; nw.reserve(ord[i - 1].size() + ord[i].size());
			int p = 0, q = 0;
			while (p < ord[i - 1].size() || q < ord[i].size())
				if (q < ord[i].size() && low[i][q] <= p) nw.push_back(ord[i][q++]);
				else nw.push_back(ord[i - 1][p++]);
			tmp.push_back(nw);
		}
		if (ord.size() & 1) tmp.push_back(ord.back());
		swap(ord, tmp);
	}
	answer(ord[0]);
}

Compilation message

swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |   for (int i = 1; i < ord.size(); i += 2) {
      |                   ~~^~~~~~~~~~~~
swaps.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |    for (int i = 1; i < ord.size(); i += 2)
      |                    ~~^~~~~~~~~~~~
swaps.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int j = 0; j != ord[i].size(); ++j) {
      |                     ~~^~~~~~~~~~~~~~~~
swaps.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |    for (int i = 1; i < ord.size(); i += 2)
      |                    ~~^~~~~~~~~~~~
swaps.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int j = 0; j != ord[i].size(); ++j) {
      |                     ~~^~~~~~~~~~~~~~~~
swaps.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int i = 1; i < ord.size(); i += 2) {
      |                   ~~^~~~~~~~~~~~
swaps.cpp:48:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    while (p < ord[i - 1].size() || q < ord[i].size())
      |           ~~^~~~~~~~~~~~~~~~~~~
swaps.cpp:48:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |    while (p < ord[i - 1].size() || q < ord[i].size())
      |                                    ~~^~~~~~~~~~~~~~~
swaps.cpp:49:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     if (q < ord[i].size() && low[i][q] <= p) nw.push_back(ord[i][q++]);
      |         ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 200 KB Not correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 200 KB Not correct
2 Halted 0 ms 0 KB -