Submission #119135

# Submission time Handle Problem Language Result Execution time Memory
119135 2019-06-20T12:30:20 Z tinjyu Ancient Books (IOI17_books) C++14
50 / 100
153 ms 22904 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
long long int tag[1000005];
int l[1000005],r[1000005];
long long int ans;
long long minimum_walk(std::vector<int> p, int s) {
	int n=p.size();
	int t=0;
	int far=0;
	for(int i=0;i<n;i++)
	{
		if(i==p[i])continue;
		ans+=abs(i-p[i]);
		if(i>p[i])
		{
			tag[p[i]]++;
			tag[i]--;
		}
		else
		{
			tag[i]++;
			tag[p[i]]--;
		}
	}
	
	for(int i=1;i<n;i++)tag[i]+=tag[i-1];
	int r=0;
	for(int i=n-1;i>=0;i--)
	{
		if(tag[i]!=0)
		{
			r=i+1;
			break;
		}
	}
	for(int i=0;i<r;i++)
	{
		if(tag[i]==0)ans+=2;
	}
	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:9:6: warning: unused variable 't' [-Wunused-variable]
  int t=0;
      ^
books.cpp:10:6: warning: unused variable 'far' [-Wunused-variable]
  int far=0;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 153 ms 22740 KB Output is correct
31 Correct 153 ms 22776 KB Output is correct
32 Correct 122 ms 22776 KB Output is correct
33 Correct 136 ms 22772 KB Output is correct
34 Correct 141 ms 22800 KB Output is correct
35 Correct 137 ms 22720 KB Output is correct
36 Correct 130 ms 22904 KB Output is correct
37 Correct 142 ms 22784 KB Output is correct
38 Correct 139 ms 22776 KB Output is correct
39 Correct 145 ms 22840 KB Output is correct
40 Correct 147 ms 22764 KB Output is correct
41 Correct 146 ms 22752 KB Output is correct
42 Correct 150 ms 22776 KB Output is correct
43 Correct 132 ms 22768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 153 ms 22740 KB Output is correct
31 Correct 153 ms 22776 KB Output is correct
32 Correct 122 ms 22776 KB Output is correct
33 Correct 136 ms 22772 KB Output is correct
34 Correct 141 ms 22800 KB Output is correct
35 Correct 137 ms 22720 KB Output is correct
36 Correct 130 ms 22904 KB Output is correct
37 Correct 142 ms 22784 KB Output is correct
38 Correct 139 ms 22776 KB Output is correct
39 Correct 145 ms 22840 KB Output is correct
40 Correct 147 ms 22764 KB Output is correct
41 Correct 146 ms 22752 KB Output is correct
42 Correct 150 ms 22776 KB Output is correct
43 Correct 132 ms 22768 KB Output is correct
44 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -