답안 #780529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
780529 2023-07-12T09:54:02 Z I_Love_EliskaM_ 고대 책들 (IOI17_books) C++14
50 / 100
105 ms 20312 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int a, int b) {return a+rng()%(b-a+1);}
#define all(x) x.begin(),x.end()
using ll = long long;

int ok(vector<int>&a){forn(i,a.size())if(a[i]!=i)return 0;return 1;}

ll minimum_walk(vector<int>a, int st) {
	if (ok(a)) return 0;
	ll ans=0;
	int n=a.size(); if (st!=0) return 0;

	vector<pi> v;
	vector<int> vis(n,0);

	int L=0, R=n-1;
	while (a[R]==R) --R;

	forn(i,n) {
		if (i<L || R<i) continue;
		if (vis[i]) continue;
		ll f=0;
		int l=n, r=-1;
		int p=i;
		while (!vis[p]) {
			vis[p]=1;
			l=min(l,p); r=max(r,p);
			f+=abs(a[p]-p);
			p=a[p];
		}
		v.pb({l,r});
		ans+=f;
	}
	sort(all(v));
	if (v.size()) ans-=2;
	int r=-1;
	for(auto&x:v) {
		if (x.f>r) ans+=2;
		r=max(r,x.s);
	}
	return ans;

}

Compilation message

books.cpp: In function 'int ok(std::vector<int>&)':
books.cpp:4:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forn(i,n) for(int i=0;i<n;++i)
......
   14 | int ok(vector<int>&a){forn(i,a.size())if(a[i]!=i)return 0;return 1;}
      |                            ~~~~~~~~~~
books.cpp:14:23: note: in expansion of macro 'forn'
   14 | int ok(vector<int>&a){forn(i,a.size())if(a[i]!=i)return 0;return 1;}
      |                       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 100 ms 12044 KB Output is correct
31 Correct 103 ms 11980 KB Output is correct
32 Correct 80 ms 8052 KB Output is correct
33 Correct 97 ms 20312 KB Output is correct
34 Correct 99 ms 20264 KB Output is correct
35 Correct 100 ms 20312 KB Output is correct
36 Correct 89 ms 14180 KB Output is correct
37 Correct 105 ms 12648 KB Output is correct
38 Correct 79 ms 12160 KB Output is correct
39 Correct 82 ms 12024 KB Output is correct
40 Correct 87 ms 11980 KB Output is correct
41 Correct 92 ms 12020 KB Output is correct
42 Correct 90 ms 12012 KB Output is correct
43 Correct 102 ms 20280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 100 ms 12044 KB Output is correct
31 Correct 103 ms 11980 KB Output is correct
32 Correct 80 ms 8052 KB Output is correct
33 Correct 97 ms 20312 KB Output is correct
34 Correct 99 ms 20264 KB Output is correct
35 Correct 100 ms 20312 KB Output is correct
36 Correct 89 ms 14180 KB Output is correct
37 Correct 105 ms 12648 KB Output is correct
38 Correct 79 ms 12160 KB Output is correct
39 Correct 82 ms 12024 KB Output is correct
40 Correct 87 ms 11980 KB Output is correct
41 Correct 92 ms 12020 KB Output is correct
42 Correct 90 ms 12012 KB Output is correct
43 Correct 102 ms 20280 KB Output is correct
44 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '0'
45 Halted 0 ms 0 KB -