답안 #959762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
959762 2024-04-09T03:59:11 Z josanneo22 The Collection Game (BOI21_swaps) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define L(i,j,k) for(int i=(j);i<=(k);++i)
#define R(i,j,k) for(int i=(j);i>=(k);--i)
#define rep(i, n) L(i, 1, n)
#define all(x) x.begin(),x.end()
#define me(x,a) memset(x,a,sizeof(x))

#include<random>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      
#include "swaps.h"

const int nax = 505;
int a[nax];

void N2(int N, int V) {
	L(i, 1, N) a[i] = i;
	L(i, 1, N) L(j, i + 1, N) {
		schedule(a[i], a[j]);
		vector<int> res = visit();
		if (res[0] == 0) swap(a[i], a[j]);
	}
	vector<int> ans;
	L(i, 1, N) ans.push_back(a[i]);
	answer(ans);
	return;
}

void merge(int l, int r) {
	if (l == r) return;
	int mid = (l + r) >> 1;
	merge(l, mid); merge(mid + 1, r);
	int LP = l, RP = mid + 1;
	vector<int> T;
	while (1) {
		if (LP <= mid && RP <= r) {
			schedule(a[LP], a[RP]);
			vector<int> res = visit();
			if (res[0] == 1) {
				T.push_back(a[LP]);
				LP++;
			}
			else {
				T.push_back(a[RP]);
				RP++;
			}
		}
		else if (LP == mid + 1 && RP <= r) {
			T.push_back(a[RP]);
			RP++;
		}
		else if (LP <= mid && RP == r + 1) {
			T.push_back(a[LP]);
			LP++;
		}
		if (LP == mid + 1 && RP == r + 1) break;
	}
	L(i, l, r) a[i] = T[i - l];
}
void merge_sol(int N, int V) {
	L(i, 1, N) a[i] = i;
	merge(1, N);
	vector<int> ans;
	L(i, 1, N) ans.push_back(a[i]);
	answer(ans);
	return;
}
void odd_even(int N,int V) {
	L(i, 1, N) a[i] = i;
	int par = 1;
	for (int t = 0; t < n; t++) {
		int st = 1 + (par == 1);
		vector<pair<int,int>> q;
		for (int i = st; i + 1 <= N; i += 2) {
			schedule(a[st], a[st + 1]);
			q.push_back(make_pair(st, st + 1));
		}
		vector<int> res = visit();
		for (int i = 0; i < res.size(); i++) {
			if (res[i] == 0) {
				swap(a[q[i].first], a[q[i].second]);
			}
		}
		par ^= 1;
	}
	vector<int> ans;
	L(i, 1, N) ans.push_back(a[i]);
	answer(ans);
	return;
}
void solve(int N, int V) {
	int costN_2 = 0;
	L(i, 1, N) L(j, i + 1, N) costN_2++;
	if (costN_2 <= V) N2(N, V);
	if (N <= 500 && N * 9 <= V) merge_sol(N, V);
	odd_even(N, V);
	return;
}

Compilation message

swaps.cpp: In function 'void odd_even(int, int)':
swaps.cpp:74:22: error: 'n' was not declared in this scope
   74 |  for (int t = 0; t < n; t++) {
      |                      ^
swaps.cpp:82:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |   for (int i = 0; i < res.size(); i++) {
      |                   ~~^~~~~~~~~~~~