# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
704385 |
2023-03-02T05:06:55 Z |
vjudge1 |
Park (JOI17_park) |
C++17 |
|
399 ms |
668 KB |
#include "park.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 2000;
static int adj[1400];
int n;
vector<pair<int,int>> res;
int help(int a,int b,bool some = false) {
if(a > b) swap(a,b);
return Ask(a,b,adj);
}
void sub1() {
for(int i = 0;i < n;i++) {
for(int j = i + 1;j < n;j++) {
adj[i] = 1;
adj[j] = 1;
if(help(i,j)) {
res.push_back({i,j});
}
adj[i] = 0;
adj[j] = 0;
}
}
for(auto u : res) {
Answer(u.first,u.second);
}
}
int kq[N + 1];
mt19937 rnd(time(0));
void process(vector<int> curr,int base) {
kq[base] = curr[0];
kq[base + (int)curr.size() - 1] = curr.back();
if(curr.size() <= 3) {
for(int i = 0;i < curr.size();i++) {
kq[i + base] = curr[i];
}
return;
}
int idx = rnd() % ((int)curr.size() - 2);
int val = curr[idx + 1];
for(int i = 0;i < n;i++) {
adj[i] = true;
}
vector<int> le,ri;
le.push_back(curr[0]);
ri.push_back(val);
for(int i = 1;i < curr.size() - 1;i++) {
if(curr[i] == val) continue;
adj[curr[i]] = false;
if(help(curr[0],val)) {
ri.push_back(curr[i]);
} else {
le.push_back(curr[i]);
}
adj[curr[i]] = true;
}
le.push_back(val);
ri.push_back(curr.back());
process(le,base);
process(ri,base + (int)le.size() - 1);
}
int my(int i) {
return rnd() % i;
}
void ans(int a,int b) {
if(a > b) swap(a,b);
Answer(a,b);
}
void sub2() {
vector<int> asd;
for(int i = 1;i < n;i++) {
asd.push_back(i);
}
random_shuffle(asd.begin(),asd.end(),my);
asd.push_back(n - 1);
reverse(asd.begin(),asd.end());
asd.push_back(0);
reverse(asd.begin(),asd.end());
process(asd,0);
for(int i = 1;i < n;i++) {
ans(kq[i],kq[i - 1]);
}
}
vector<int> before,after;
bool vis[N + 1];
void dfs(int s,vector<int> comp) {
if(comp.size() == 0) return;
// cout<<s<<endl;
// for(auto u : comp) {
// cout<<u<<" ";
// }
// cout<<endl;
vector<int> asd;
vis[s] = true;
for(int i = 0;i < n;i++) {
adj[i] = false;
}
for(auto i : comp) {
if(vis[i]) continue;
adj[s] = true;
adj[i] = true;
if(help(s,i)) {
asd.push_back(i);
res.push_back({s,i});
vis[i] = true;
}
adj[s] = false;
adj[i] = false;
}
vector<int> some;
for(auto u : asd) {
some.clear();
for(int i = 0;i < n;i++) {
adj[i] = true;
}
adj[u] = false;
for(auto x : comp) {
if(vis[x]) continue;
// if(u == 1 && x == 14) {
// cout<<"HERE"<<" "<<help(0,x)<<endl;
// for(int j = 0;j < n;j++) {
// cout<<j<<" "<<adj[j]<<endl;
// }
// }
bool asd = false;
if(u == 1 && x == 14) {
asd = true;
}
if(!help(0,x,asd)) {
some.push_back(x);
}
}
adj[u] = true;
dfs(u,some);
}
}
void sub3() {
vector<int> st;
for(int i = 1;i < n;i++) {
st.push_back(i);
}
dfs(0,st);
for(auto u : res) {
// cout<<u.first<<" "<<u.second<<endl;
ans(u.first,u.second);
}
}
void Detect(int T, int N) {
n = N;
if(T == 1) {
sub1();
return;
}
if(T == 2) {
sub2();
return;
}
if(T == 3) {
sub3();
return;
}
}
Compilation message
park.cpp: In function 'void process(std::vector<int>, int)':
park.cpp:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i = 0;i < curr.size();i++) {
| ~~^~~~~~~~~~~~~
park.cpp:63:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 1;i < curr.size() - 1;i++) {
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
178 ms |
500 KB |
Output is correct |
2 |
Correct |
85 ms |
528 KB |
Output is correct |
3 |
Correct |
100 ms |
504 KB |
Output is correct |
4 |
Correct |
173 ms |
532 KB |
Output is correct |
5 |
Correct |
180 ms |
524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
363 ms |
424 KB |
Output is correct |
2 |
Correct |
396 ms |
460 KB |
Output is correct |
3 |
Correct |
390 ms |
416 KB |
Output is correct |
4 |
Correct |
256 ms |
428 KB |
Output is correct |
5 |
Correct |
334 ms |
420 KB |
Output is correct |
6 |
Correct |
353 ms |
524 KB |
Output is correct |
7 |
Correct |
282 ms |
664 KB |
Output is correct |
8 |
Correct |
399 ms |
668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Wrong Answer[6] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Wrong Answer[6] |
2 |
Halted |
0 ms |
0 KB |
- |