이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <random>
#include <cassert>
#include <numeric>
#include <algorithm>
#include "meetings.h"
using namespace std;
#define f first
#define s second
vector<pair<int, int>> ans;
mt19937 rd(4315143);
int query(int x, int y, int z) {
if (x == y || x == z) return x;
if (y == z) return y;
return Query(x, y, z);
}
void solve(vector<int> v) {
if (v.size() <= 1) return;
shuffle(v.begin(), v.end(), rd);
int x = v[0], y = v[1];
for (int i = 2, ret; i < v.size(); i++) {
ret = query(x, y, v[i]);
if (ret == x) {
x = v[i];
} else if (ret == y) {
y = v[i];
}
}
map<int, vector<int>> groups;
for (int i = 0, ret; i < v.size(); i++) {
if (v[i] == x || v[i] == y) continue;
ret = query(x, y, v[i]);
groups[ret].push_back(v[i]);
}
vector<int> curr;
curr.push_back(x);
curr.push_back(y);
for (pair<int, vector<int>> g : groups) {
curr.push_back(g.f);
}
sort(curr.begin(), curr.end(), [&] (int a, int b) {
int ret = query(x, a, b);
return ret == a;
});
for (int i = 0; i < curr.size() - 1; i++) {
ans.push_back({curr[i], curr[i + 1]});
}
for (pair<int, vector<int>> g : groups) {
solve(g.s);
}
}
void Solve(int N) {
vector<int> tmp(N);
iota(tmp.begin(), tmp.end(), 0);
solve(tmp);
for (auto [x, y] : ans) {
assert(x != y);
if (y < x) swap(x, y);
Bridge(x, y);
}
}
컴파일 시 표준 에러 (stderr) 메시지
meetings.cpp: In function 'void solve(std::vector<int>)':
meetings.cpp:28:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = 2, ret; i < v.size(); i++) {
| ~~^~~~~~~~~~
meetings.cpp:37:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 0, ret; i < v.size(); i++) {
| ~~^~~~~~~~~~
meetings.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int i = 0; i < curr.size() - 1; i++) {
| ~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |