답안 #375451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
375451 2021-03-09T12:22:13 Z Seanliu Meetings (JOI19_meetings) C++17
29 / 100
2000 ms 1216 KB
#include "meetings.h"
#include <iostream>
#include <unordered_map>	
#include <algorithm>
#include <vector>
using namespace std;
 
const int maxN = 2e3 + 326;
vector<int> adj[maxN];

void addEdge(int a, int b){
	//cout << "Adding: " << a << ", " << b << endl;
	if(a > b) Bridge(b, a);
	else Bridge(a, b);
}
 
void solve(vector<int> vec){
	if(vec.size() == 1) return;
	if(vec.size() == 2){
		addEdge(vec[0], vec[1]);
		return;
	}
	//cout << "vec = "; for(int x : vec) cout << x << " "; cout << endl;
	unordered_map<int, vector<int>> mp;
	vector<int> nv = vector<int>();
	int a = vec[0], b = vec[1];
	for(int i = 2; i < vec.size(); i++){
		int res = Query(a, b, vec[i]);
		if(res == a) a = vec[i];
		if(res == b) b = vec[i];
	}
	//cout << "a = " << a << ", b = " << b << endl;
	mp[a] = mp[b] = vector<int>();
	mp[a].push_back(a);
	mp[b].push_back(b);
	for(int i = 0; i < vec.size(); i++){
		if(vec[i] == a || vec[i] == b) continue;
		int res = Query(a, b, vec[i]);
		if(!mp.count(res)) mp[res] = vector<int>();
		mp[res].push_back(vec[i]);
	}
	for(auto [x, v] : mp){
		//cout << "x = " << x << ", v = "; for(int y : v) cout << y << " "; cout << endl;
		solve(v);
		if(x != a && x != b) nv.push_back(x);
	}
	sort(nv.begin(), nv.end(), [&](int x, int y){
		return Query(a, x, y) == x;
	});
	//cout << "OK\n";
	//cout << "nv = " << nv.size() << ", vec: " << vec.size() << endl;
	if(nv.size()){
		for(int i = 0; i < nv.size() - 1; i++) addEdge(nv[i], nv[i + 1]);
		addEdge(a, nv[0]);
		addEdge(b, nv[nv.size() - 1]);
	} else addEdge(a, b);
}
 
void Solve(int N){
	vector<int> jizz = vector<int>();
	for(int i = 0; i < N; i++) jizz.push_back(i);
	solve(jizz);
}

Compilation message

meetings.cpp: In function 'void solve(std::vector<int>)':
meetings.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  for(int i = 2; i < vec.size(); i++){
      |                 ~~^~~~~~~~~~~~
meetings.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 < vec.size(); i++){
      |                 ~~^~~~~~~~~~~~
meetings.cpp:53:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int i = 0; i < nv.size() - 1; i++) addEdge(nv[i], nv[i + 1]);
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 396 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 512 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 396 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 9 ms 492 KB Output is correct
28 Correct 11 ms 492 KB Output is correct
29 Correct 11 ms 492 KB Output is correct
30 Correct 8 ms 492 KB Output is correct
31 Correct 8 ms 492 KB Output is correct
32 Correct 11 ms 620 KB Output is correct
33 Correct 17 ms 492 KB Output is correct
34 Correct 22 ms 492 KB Output is correct
35 Correct 22 ms 492 KB Output is correct
36 Correct 12 ms 492 KB Output is correct
37 Correct 28 ms 492 KB Output is correct
38 Correct 23 ms 620 KB Output is correct
39 Correct 17 ms 496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 794 ms 952 KB Output is correct
2 Correct 958 ms 748 KB Output is correct
3 Correct 919 ms 748 KB Output is correct
4 Correct 897 ms 1004 KB Output is correct
5 Correct 639 ms 876 KB Output is correct
6 Correct 714 ms 696 KB Output is correct
7 Correct 925 ms 1004 KB Output is correct
8 Correct 1054 ms 748 KB Output is correct
9 Correct 1050 ms 768 KB Output is correct
10 Correct 986 ms 940 KB Output is correct
11 Correct 1177 ms 780 KB Output is correct
12 Correct 552 ms 748 KB Output is correct
13 Correct 429 ms 876 KB Output is correct
14 Correct 958 ms 876 KB Output is correct
15 Correct 592 ms 876 KB Output is correct
16 Correct 741 ms 748 KB Output is correct
17 Correct 938 ms 780 KB Output is correct
18 Execution timed out 2323 ms 1216 KB Time limit exceeded
19 Halted 0 ms 0 KB -