# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
67857 |
2018-08-15T11:24:13 Z |
reality |
Park (JOI17_park) |
C++17 |
|
589 ms |
1716 KB |
#include "park.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
static const int N = 2048;
static int n;
static int mark[N];
int called = 0;
static int get(int a,int b,vi v) {
if (a > b)
swap(a,b);
if (!v[a] || !v[b])
return 0;
++called;
return Ask(a,b,v.data());
}
static int Go(int a,int b,vi w,vi was) {
const int sz = w.size();
int l = 0,r = sz;
int Last = -1;
while (l < r) {
int m = (l + r) / 2;
for (int i = 0;i < m;++i)
was[w[i]] = 1;
for (int i = m;i < sz;++i)
was[w[i]] = 0;
Last = get(a,b,was);
if (Last)
r = m;
else
l = m + 1;
}
if (!l)
return -1;
for (int i = 0;i < l;++i)
was[w[i]] = 1;
for (int i = l;i < sz;++i)
was[w[i]] = 0;
if (!get(a,b,was))
return -1;
return w[l - 1];
}
set < int > G[N];
void add_edge(int A,int B) {
if (A > B)
swap(A,B);
Answer(A,B);
G[A].insert(B);
G[B].insert(A);
}
vi order;
int W[N];
vi w;
void dfs(int v) {
order.pb(v);
W[v] = 1;
for (auto it : G[v])
if (!W[it] && w[it])
dfs(it);
}
void del(int v) {
w[v] = 0;
for (auto it : G[v])
if (w[it])
del(it);
}
void find_edges(int node) {
mark[node] = 1;
w.resize(n);
for (int i = 0;i < n;++i)
w[i] = mark[i];
for (int i = 0;i < n;++i)
while (i != node && w[i]) {
if (get(node,i,w)) {
order.clear();
for (int j = 0;j < n;++j)
W[j] = 0;
dfs(i);
vi was(n,0);
was[node] = 1;
int g = Go(node,i,order,was);
if (g != -1)
add_edge(node,g),w[g] = 0;
else {
break;
}
} else {
del(i);
}
}
}
static void Next(int node) {
set < int > ss;
vi was(n,0);
for (int i = 0;i < n;++i)
if (!mark[i] && i != node)
ss.insert(i);
else
was[i] = 1;
vi nxt;
do {
int poss = Go(0,node,vi(all(ss)),was);
if (poss != -1) {
nxt.pb(poss);
ss.erase(poss);
was[poss] = 1;
} else {
break;
}
} while (1);
nxt.pb(node);
for (auto it : nxt)
find_edges(it);
}
void Detect(int T, int NN) {
n = NN;
mark[0] = 1;
for (int i = 1;i < n;++i)
if (!mark[i])
Next(i);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
17 ms |
504 KB |
Output is correct |
3 |
Correct |
17 ms |
708 KB |
Output is correct |
4 |
Correct |
32 ms |
708 KB |
Output is correct |
5 |
Correct |
72 ms |
752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
884 KB |
Wrong Answer[5] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
474 ms |
1060 KB |
Output is correct |
2 |
Correct |
497 ms |
1248 KB |
Output is correct |
3 |
Correct |
526 ms |
1264 KB |
Output is correct |
4 |
Correct |
506 ms |
1312 KB |
Output is correct |
5 |
Correct |
511 ms |
1480 KB |
Output is correct |
6 |
Correct |
471 ms |
1532 KB |
Output is correct |
7 |
Correct |
496 ms |
1532 KB |
Output is correct |
8 |
Correct |
562 ms |
1532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
1532 KB |
Output is correct |
2 |
Correct |
528 ms |
1656 KB |
Output is correct |
3 |
Correct |
519 ms |
1716 KB |
Output is correct |
4 |
Correct |
484 ms |
1716 KB |
Output is correct |
5 |
Incorrect |
254 ms |
1716 KB |
Wrong Answer[5] |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
589 ms |
1716 KB |
Output is correct |
2 |
Correct |
551 ms |
1716 KB |
Output is correct |
3 |
Correct |
525 ms |
1716 KB |
Output is correct |
4 |
Incorrect |
460 ms |
1716 KB |
Wrong Answer[5] |
5 |
Halted |
0 ms |
0 KB |
- |