# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
67889 |
2018-08-15T12:00:09 Z |
reality |
Park (JOI17_park) |
C++17 |
|
651 ms |
2672 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 = 0;
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];
int Place = 0;
for (int i = 0;i < n;++i)
while (i != node && w[i]) {
++Place;
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);
}
}
}
int qq[N];
static void Next(int node) {
qq[node] = 1;
vi was(n,0);
for (int i = 0;i < n;++i)
was[i] = mark[i] || qq[i];
while (!get(0,node,was)) {
vi h;
for (int i = 0;i < n;++i)
if (!qq[i] && !mark[i])
h.pb(i);
else
was[i] = 1;
int g = Go(0,node,h,was);
if (g != -1)
Next(g);
else break;
}
find_edges(node);
}
void Detect(int T, int NN) {
n = NN;
mark[0] = 1;
for (int i = 1;i < n;++i)
if (!mark[i]) {
Next(i);
for (int j = 0;j < n;++j)
qq[j] = 0;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
16 ms |
488 KB |
Output is correct |
3 |
Correct |
14 ms |
660 KB |
Output is correct |
4 |
Correct |
31 ms |
660 KB |
Output is correct |
5 |
Correct |
54 ms |
736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
646 ms |
1160 KB |
Output is correct |
2 |
Correct |
231 ms |
1160 KB |
Output is correct |
3 |
Correct |
294 ms |
1208 KB |
Output is correct |
4 |
Correct |
597 ms |
1272 KB |
Output is correct |
5 |
Correct |
584 ms |
1340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
1436 KB |
Output is correct |
2 |
Correct |
385 ms |
1436 KB |
Output is correct |
3 |
Correct |
409 ms |
1436 KB |
Output is correct |
4 |
Correct |
350 ms |
1436 KB |
Output is correct |
5 |
Correct |
458 ms |
1468 KB |
Output is correct |
6 |
Correct |
383 ms |
1468 KB |
Output is correct |
7 |
Correct |
320 ms |
1468 KB |
Output is correct |
8 |
Correct |
417 ms |
1532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
202 ms |
1532 KB |
Output is correct |
2 |
Correct |
475 ms |
1544 KB |
Output is correct |
3 |
Correct |
463 ms |
1544 KB |
Output is correct |
4 |
Correct |
453 ms |
1600 KB |
Output is correct |
5 |
Correct |
471 ms |
1620 KB |
Output is correct |
6 |
Correct |
487 ms |
1768 KB |
Output is correct |
7 |
Correct |
565 ms |
1820 KB |
Output is correct |
8 |
Correct |
477 ms |
1820 KB |
Output is correct |
9 |
Correct |
448 ms |
1820 KB |
Output is correct |
10 |
Correct |
463 ms |
1820 KB |
Output is correct |
11 |
Correct |
462 ms |
1820 KB |
Output is correct |
12 |
Correct |
485 ms |
1904 KB |
Output is correct |
13 |
Correct |
595 ms |
1948 KB |
Output is correct |
14 |
Correct |
483 ms |
1948 KB |
Output is correct |
15 |
Correct |
496 ms |
1948 KB |
Output is correct |
16 |
Correct |
393 ms |
1948 KB |
Output is correct |
17 |
Correct |
651 ms |
2012 KB |
Output is correct |
18 |
Correct |
468 ms |
2012 KB |
Output is correct |
19 |
Correct |
486 ms |
2012 KB |
Output is correct |
20 |
Correct |
488 ms |
2012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
516 ms |
2012 KB |
Output is correct |
2 |
Correct |
489 ms |
2012 KB |
Output is correct |
3 |
Correct |
418 ms |
2132 KB |
Output is correct |
4 |
Correct |
533 ms |
2156 KB |
Output is correct |
5 |
Correct |
532 ms |
2156 KB |
Output is correct |
6 |
Correct |
596 ms |
2196 KB |
Output is correct |
7 |
Correct |
583 ms |
2216 KB |
Output is correct |
8 |
Correct |
522 ms |
2368 KB |
Output is correct |
9 |
Correct |
505 ms |
2368 KB |
Output is correct |
10 |
Correct |
495 ms |
2368 KB |
Output is correct |
11 |
Correct |
501 ms |
2368 KB |
Output is correct |
12 |
Correct |
558 ms |
2368 KB |
Output is correct |
13 |
Correct |
484 ms |
2368 KB |
Output is correct |
14 |
Correct |
539 ms |
2368 KB |
Output is correct |
15 |
Correct |
491 ms |
2368 KB |
Output is correct |
16 |
Correct |
415 ms |
2376 KB |
Output is correct |
17 |
Correct |
629 ms |
2672 KB |
Output is correct |
18 |
Correct |
433 ms |
2672 KB |
Output is correct |