# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
525396 |
2022-02-11T14:10:11 Z |
idas |
Stations (IOI20_stations) |
C++17 |
|
994 ms |
772 KB |
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=1e3+10;
int dp[N], lb[N], lst;
bool v[N];
vi ad[N];
void build(int u, int pst)
{
for(auto x : ad[u]){
if(x==pst) continue;
build(x, u);
dp[u]+=dp[x];
}
dp[u]++;
}
void dfs(int u, int pst, bool mx)
{
if(mx){
while(v[lst]) lst--;
lb[u]=lst;
v[lst]=true;
}
for(auto x : ad[u]){
if(x==pst) continue;
if(mx){
int now=lb[u];
while(v[now]) now--;
lb[x]=now-dp[x]+1;
assert(!v[lb[x]]);
v[lb[x]]=true;
}
dfs(x, u, !mx);
}
}
vi label(int n, int k, vi uu, vi vv)
{
FOR(i, 0, n+1) ad[i].clear(), v[i]=false, dp[i]=0, lb[i]=0;
FOR(i, 0, n-1)
{
ad[uu[i]].pb(vv[i]);
ad[vv[i]].pb(uu[i]);
}
lst=n;
build(0, -1);
dfs(0, -1, true);
vi ans;
FOR(i, 0, n) ans.pb(lb[i]);
return ans;
}
int find_next_station(int s, int t, vi c)
{
for(auto x : c){
if(x==t){
return t;
}
}
if(s<c[0]){
if(t<s){
return le(c);
}
FOR(i, 0, sz(c)-1)
{
if(c[i]>t){
return c[i];
}
}
return le(c);
}
else{
if(t>s){
return c[0];
}
for(int i=sz(c)-1; i>0; i--){
if(c[i]<t){
return c[i];
}
}
return c[0];
}
}
/*int main()
{
setIO();
/*int nn, kk; cin >> nn >> kk;
vi ar(nn-1), br(nn-1);
FOR(i, 0, nn-1)
{
cin >> ar[i] >> br[i];
}
for(auto x : label(nn, kk, ar, br)){
cout << x << '\n';
}*/
//cout << find_next_station(3, 4, {1,2});
//}
Compilation message
stations.cpp:123:5: warning: "/*" within comment [-Wcomment]
123 | /*int nn, kk; cin >> nn >> kk;
|
stations.cpp: In function 'void setIO(std::string)':
stations.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stations.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
526 ms |
648 KB |
Output is correct |
2 |
Correct |
427 ms |
676 KB |
Output is correct |
3 |
Correct |
994 ms |
504 KB |
Output is correct |
4 |
Correct |
740 ms |
500 KB |
Output is correct |
5 |
Correct |
534 ms |
508 KB |
Output is correct |
6 |
Correct |
490 ms |
524 KB |
Output is correct |
7 |
Correct |
382 ms |
524 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
5 ms |
476 KB |
Output is correct |
10 |
Correct |
1 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
410 ms |
584 KB |
Output is correct |
2 |
Correct |
552 ms |
512 KB |
Output is correct |
3 |
Correct |
872 ms |
504 KB |
Output is correct |
4 |
Correct |
596 ms |
404 KB |
Output is correct |
5 |
Correct |
578 ms |
512 KB |
Output is correct |
6 |
Correct |
437 ms |
496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
494 ms |
640 KB |
Output is correct |
2 |
Correct |
455 ms |
632 KB |
Output is correct |
3 |
Correct |
964 ms |
528 KB |
Output is correct |
4 |
Correct |
574 ms |
512 KB |
Output is correct |
5 |
Correct |
559 ms |
404 KB |
Output is correct |
6 |
Correct |
528 ms |
632 KB |
Output is correct |
7 |
Correct |
416 ms |
528 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
604 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
577 ms |
516 KB |
Output is correct |
12 |
Correct |
391 ms |
748 KB |
Output is correct |
13 |
Correct |
472 ms |
740 KB |
Output is correct |
14 |
Correct |
431 ms |
512 KB |
Output is correct |
15 |
Correct |
52 ms |
532 KB |
Output is correct |
16 |
Correct |
66 ms |
656 KB |
Output is correct |
17 |
Correct |
103 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
765 ms |
496 KB |
Output is correct |
2 |
Correct |
572 ms |
516 KB |
Output is correct |
3 |
Correct |
643 ms |
516 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
488 KB |
Output is correct |
7 |
Correct |
545 ms |
492 KB |
Output is correct |
8 |
Correct |
849 ms |
488 KB |
Output is correct |
9 |
Correct |
602 ms |
512 KB |
Output is correct |
10 |
Correct |
533 ms |
404 KB |
Output is correct |
11 |
Correct |
6 ms |
476 KB |
Output is correct |
12 |
Correct |
6 ms |
492 KB |
Output is correct |
13 |
Correct |
4 ms |
576 KB |
Output is correct |
14 |
Correct |
3 ms |
600 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
412 ms |
500 KB |
Output is correct |
17 |
Correct |
446 ms |
504 KB |
Output is correct |
18 |
Correct |
443 ms |
556 KB |
Output is correct |
19 |
Correct |
450 ms |
400 KB |
Output is correct |
20 |
Correct |
468 ms |
520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
484 ms |
632 KB |
Output is correct |
2 |
Correct |
447 ms |
520 KB |
Output is correct |
3 |
Correct |
893 ms |
508 KB |
Output is correct |
4 |
Correct |
624 ms |
400 KB |
Output is correct |
5 |
Correct |
534 ms |
496 KB |
Output is correct |
6 |
Correct |
442 ms |
640 KB |
Output is correct |
7 |
Correct |
423 ms |
528 KB |
Output is correct |
8 |
Correct |
3 ms |
736 KB |
Output is correct |
9 |
Correct |
4 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
393 ms |
508 KB |
Output is correct |
12 |
Correct |
547 ms |
508 KB |
Output is correct |
13 |
Correct |
862 ms |
400 KB |
Output is correct |
14 |
Correct |
574 ms |
512 KB |
Output is correct |
15 |
Correct |
608 ms |
504 KB |
Output is correct |
16 |
Correct |
429 ms |
504 KB |
Output is correct |
17 |
Correct |
652 ms |
508 KB |
Output is correct |
18 |
Correct |
413 ms |
636 KB |
Output is correct |
19 |
Correct |
570 ms |
648 KB |
Output is correct |
20 |
Correct |
464 ms |
532 KB |
Output is correct |
21 |
Correct |
47 ms |
576 KB |
Output is correct |
22 |
Correct |
68 ms |
704 KB |
Output is correct |
23 |
Correct |
96 ms |
656 KB |
Output is correct |
24 |
Correct |
6 ms |
476 KB |
Output is correct |
25 |
Correct |
4 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
4 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
476 KB |
Output is correct |
29 |
Correct |
490 ms |
400 KB |
Output is correct |
30 |
Correct |
475 ms |
400 KB |
Output is correct |
31 |
Correct |
506 ms |
404 KB |
Output is correct |
32 |
Correct |
469 ms |
404 KB |
Output is correct |
33 |
Correct |
444 ms |
504 KB |
Output is correct |
34 |
Correct |
333 ms |
652 KB |
Output is correct |
35 |
Correct |
416 ms |
652 KB |
Output is correct |
36 |
Correct |
386 ms |
636 KB |
Output is correct |
37 |
Correct |
411 ms |
604 KB |
Output is correct |
38 |
Correct |
462 ms |
520 KB |
Output is correct |
39 |
Correct |
450 ms |
636 KB |
Output is correct |
40 |
Correct |
456 ms |
612 KB |
Output is correct |
41 |
Correct |
342 ms |
772 KB |
Output is correct |
42 |
Correct |
60 ms |
532 KB |
Output is correct |
43 |
Correct |
101 ms |
644 KB |
Output is correct |
44 |
Correct |
115 ms |
544 KB |
Output is correct |
45 |
Correct |
169 ms |
528 KB |
Output is correct |
46 |
Correct |
303 ms |
512 KB |
Output is correct |
47 |
Correct |
267 ms |
528 KB |
Output is correct |
48 |
Correct |
59 ms |
660 KB |
Output is correct |
49 |
Correct |
56 ms |
704 KB |
Output is correct |