답안 #439508

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439508 2021-06-30T06:59:52 Z 8e7 Monster Game (JOI21_monster) C++17
86 / 100
142 ms 1364 KB
#include "monster.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <time.h>
#include <random>
 
#define maxn 1005
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ";debug(b ...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
namespace {
	int cnt[maxn];
	bool res[maxn][maxn];
	bool found[maxn][maxn];
}  // namespace
bool que(int a, int b) {
	if (found[a][b]) return res[a][b];
	bool ret = Query(a, b);
	res[a][b] = ret, res[b][a] = ret ^ 1;
	return ret;
}
void mergesort(vector<int> &v) {
	if (v.size() <= 1) {
		return;
	}
	vector<int> lef, rig;
	for (int i = 0;i < v.size();i++) {
		if (i < (v.size() / 2)) lef.push_back(v[i]);
		else rig.push_back(v[i]);
	}
	mergesort(lef), mergesort(rig);	
	vector<int> ret;
	int ind = 0;
	for (int i = 0;i < lef.size();i++) {
		while (ind < rig.size() && que(lef[i], rig[ind])) {
			ret.push_back(rig[ind]);
			ind++;
		}
		ret.push_back(lef[i]);
	}
	while (ind < rig.size()) ret.push_back(rig[ind++]);
	v = ret;
}
 
vector<int> Solve(int N) {
	vector<int> ret;
	vector<int> cand;
	for (int i = 0;i < N;i++) cand.push_back(i);
	mergesort(cand);
	//pary(cand.begin(), cand.end());
	vector<pii> cur;
	for (int i = N - 1;i >= 0;i--) {
		int loss = 0;	
		for (auto &j:cur) {
			if (que(cand[i], cand[j.ff])) j.ss++;
			else loss++;	
		}
		for (int j = cur.size() - 1;j >= 0;j--) {
			if (cur[j].ss > 1) {
				cur.erase(cur.begin() + j);		
			}
		}
		if (loss < 2) {
			cur.push_back({i, loss});
		}
	}	
	//cout << 7122 << endl;
	//for (auto i:cur) cout << i.ff << " ";
	//cout << endl;
	int big;
	if (cur.size() == 2) {
		if (que(cand[cur[0].ff], cand[cur[1].ff])) big = cur[1].ff;
		else big = cur[0].ff;
	} else {
		big = cur[0].ff;
		for (int i = 0;i < 2;i++) {
			if (cur[i + 1].ff == cur[i].ff - 1) big = cur[i + 1].ff;
			else {
				break;
			}
		}
	}
	//debug(big);
	for (int i = big;i < N;i++) ret.push_back(cand[i]);
	int comp = N - 1;
	for (int i = big - 1;i >= 0;i--) {
		if (que(cand[i], cand[comp])) {
			for (int j = i;j < big;j++) ret.push_back(cand[j]);
			comp = big - 1, big = i;
		}
	}
	reverse(ret.begin(), ret.end());
	vector<int> a (N, 0);
	for (int i = 0;i < N;i++) a[ret[i]] = i;
	return a;
}

Compilation message

monster.cpp: In function 'void mergesort(std::vector<int>&)':
monster.cpp:36:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i = 0;i < v.size();i++) {
      |                 ~~^~~~~~~~~~
monster.cpp:37:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   if (i < (v.size() / 2)) lef.push_back(v[i]);
      |       ~~^~~~~~~~~~~~~~~~
monster.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (int i = 0;i < lef.size();i++) {
      |                 ~~^~~~~~~~~~~~
monster.cpp:44:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   while (ind < rig.size() && que(lef[i], rig[ind])) {
      |          ~~~~^~~~~~~~~~~~
monster.cpp:50:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  while (ind < rig.size()) ret.push_back(rig[ind++]);
      |         ~~~~^~~~~~~~~~~~
monster.cpp: At global scope:
monster.cpp:21:6: warning: '{anonymous}::cnt' defined but not used [-Wunused-variable]
   21 |  int cnt[maxn];
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 19 ms 448 KB Output is correct
17 Correct 21 ms 456 KB Output is correct
18 Correct 16 ms 456 KB Output is correct
19 Correct 18 ms 456 KB Output is correct
20 Correct 20 ms 440 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 16 ms 456 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 12 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Output is correct
2 Correct 1 ms 200 KB Output is correct
3 Correct 1 ms 200 KB Output is correct
4 Correct 1 ms 200 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 200 KB Output is correct
9 Correct 1 ms 200 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
13 Correct 1 ms 200 KB Output is correct
14 Correct 1 ms 200 KB Output is correct
15 Correct 1 ms 200 KB Output is correct
16 Correct 19 ms 448 KB Output is correct
17 Correct 21 ms 456 KB Output is correct
18 Correct 16 ms 456 KB Output is correct
19 Correct 18 ms 456 KB Output is correct
20 Correct 20 ms 440 KB Output is correct
21 Correct 1 ms 200 KB Output is correct
22 Correct 1 ms 200 KB Output is correct
23 Correct 1 ms 200 KB Output is correct
24 Correct 1 ms 200 KB Output is correct
25 Correct 1 ms 200 KB Output is correct
26 Correct 16 ms 456 KB Output is correct
27 Correct 1 ms 200 KB Output is correct
28 Correct 1 ms 200 KB Output is correct
29 Correct 1 ms 200 KB Output is correct
30 Correct 1 ms 200 KB Output is correct
31 Correct 1 ms 200 KB Output is correct
32 Correct 12 ms 456 KB Output is correct
33 Correct 93 ms 1200 KB Output is correct
34 Correct 105 ms 1320 KB Output is correct
35 Correct 105 ms 1276 KB Output is correct
36 Correct 119 ms 1280 KB Output is correct
37 Correct 125 ms 1192 KB Output is correct
38 Correct 142 ms 1196 KB Output is correct
39 Correct 76 ms 1260 KB Output is correct
40 Correct 113 ms 1216 KB Output is correct
41 Correct 68 ms 1184 KB Output is correct
42 Correct 88 ms 1216 KB Output is correct
43 Correct 67 ms 1188 KB Output is correct
44 Correct 76 ms 1216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 114 ms 1168 KB Partially correct
2 Partially correct 118 ms 1284 KB Partially correct
3 Partially correct 111 ms 1168 KB Partially correct
4 Partially correct 112 ms 1284 KB Partially correct
5 Partially correct 123 ms 1344 KB Partially correct
6 Partially correct 89 ms 1216 KB Partially correct
7 Partially correct 110 ms 1284 KB Partially correct
8 Partially correct 138 ms 1208 KB Partially correct
9 Partially correct 114 ms 1280 KB Partially correct
10 Partially correct 123 ms 1364 KB Partially correct
11 Partially correct 119 ms 1252 KB Partially correct
12 Partially correct 105 ms 1328 KB Partially correct
13 Partially correct 102 ms 1280 KB Partially correct
14 Partially correct 111 ms 1300 KB Partially correct
15 Correct 83 ms 1228 KB Output is correct
16 Correct 71 ms 1280 KB Output is correct
17 Partially correct 87 ms 1284 KB Partially correct
18 Correct 93 ms 1168 KB Output is correct