Submission #775891

# Submission time Handle Problem Language Result Execution time Memory
775891 2023-07-07T06:10:41 Z Amylopectin Ancient Books (IOI17_books) C++14
50 / 100
129 ms 28460 KB
#include "books.h"
#include <vector>
#include <algorithm>
using namespace std;
const long long mxn = 4e6 + 10;
// const long long mxn = 20;
struct we
{
	long long le,ri;
};
bool cmp(const struct we &l,const struct we &r)
{
	return l.le < r.le;
}
struct we cyc[mxn] = {};
long long ta[mxn] = {},ru,u[mxn] = {};
long long fimi(long long l,long long r)
{
	if(l < r)
		return l;
	return r;
}
long long fima(long long l,long long r)
{
	if(l > r)
		return l;
	return r;
}
long long ab(long long l)
{
	if(l < 0)
		return -l;
	return l;
}
long long minimum_walk(std::vector<int> pp, int sta) 
{
	long long i,j,n = pp.size(),m,cn,cm,fn,fm,su = 0,fii,cou
	,ble = sta,bri = sta,cmi,cva,cri,cle,cl,cr;
	for(i=0; i<n; i++)
	{
		ta[i] = pp[i];
	}
	ru = 0;
	cyc[0] = {-1,n+1};
	for(i=0; i<n; i++)
	{
		if(u[i] == 0)
		{
			cn = i;
			cou = 1;
			cyc[ru] = {i,i};
			while(1)
			{
				// if(cn <= sta)
				// {
					cyc[ru].le = fimi(cyc[ru].le,cn);
				// }
				// else 
				// {
					cyc[ru].ri = fima(cyc[ru].ri,cn);
				// }
				u[cn] = 1;
				su += ab(cn - ta[cn]);
				cn = ta[cn];
				if(cn == i)
				{
					break;
				}
				cou ++;
			}
			if(cou == 1)
			{
				// cyc[ru] = {-1,n+1};
			}
			// else if(cyc[ru].le == -1)
			// {
			// 	bri = fima(bri,cyc[ru].ri);
			// 	cyc[ru] = {-1,n+1};
			// }
			// else if(cyc[ru].ri == n+1)
			// {
			// 	ble = fimi(ble,cyc[ru].le);
			// 	cyc[ru] = {-1,n+1};
			// }
			else 
			{
				ru ++;
				// cyc[ru] = {-1,n+1};
			}
		}
	}
	sort(cyc,cyc+ru,cmp);
	cva = 0;
	cr = 0;
	for(i=0; i<ru; i++)
	{
		if(cyc[i].le <= cr)
		{
			cr = fima(cyc[i].ri,cr);
		}
		else 
		{
			cva += cyc[i].le - cr;
			cr = fima(cyc[i].ri,cr);
		}
	}

	// cmi = n+1;
	// for(i=0; i<ru; i++)
	// {
	// 	if(cyc[i].ri <= bri)
	// 	{
	// 		break;
	// 	}
	// 	cmi = fimi(cmi,cyc[i].ri - ble);
	// 	ble = fimi(cyc[i].le,ble);
	// }
	// cmi = fimi(cmi,bri - ble);

	return su + cva * 2;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:37:14: warning: unused variable 'j' [-Wunused-variable]
   37 |  long long i,j,n = pp.size(),m,cn,cm,fn,fm,su = 0,fii,cou
      |              ^
books.cpp:37:30: warning: unused variable 'm' [-Wunused-variable]
   37 |  long long i,j,n = pp.size(),m,cn,cm,fn,fm,su = 0,fii,cou
      |                              ^
books.cpp:37:35: warning: unused variable 'cm' [-Wunused-variable]
   37 |  long long i,j,n = pp.size(),m,cn,cm,fn,fm,su = 0,fii,cou
      |                                   ^~
books.cpp:37:38: warning: unused variable 'fn' [-Wunused-variable]
   37 |  long long i,j,n = pp.size(),m,cn,cm,fn,fm,su = 0,fii,cou
      |                                      ^~
books.cpp:37:41: warning: unused variable 'fm' [-Wunused-variable]
   37 |  long long i,j,n = pp.size(),m,cn,cm,fn,fm,su = 0,fii,cou
      |                                         ^~
books.cpp:37:51: warning: unused variable 'fii' [-Wunused-variable]
   37 |  long long i,j,n = pp.size(),m,cn,cm,fn,fm,su = 0,fii,cou
      |                                                   ^~~
books.cpp:38:3: warning: unused variable 'ble' [-Wunused-variable]
   38 |  ,ble = sta,bri = sta,cmi,cva,cri,cle,cl,cr;
      |   ^~~
books.cpp:38:13: warning: unused variable 'bri' [-Wunused-variable]
   38 |  ,ble = sta,bri = sta,cmi,cva,cri,cle,cl,cr;
      |             ^~~
books.cpp:38:23: warning: unused variable 'cmi' [-Wunused-variable]
   38 |  ,ble = sta,bri = sta,cmi,cva,cri,cle,cl,cr;
      |                       ^~~
books.cpp:38:31: warning: unused variable 'cri' [-Wunused-variable]
   38 |  ,ble = sta,bri = sta,cmi,cva,cri,cle,cl,cr;
      |                               ^~~
books.cpp:38:35: warning: unused variable 'cle' [-Wunused-variable]
   38 |  ,ble = sta,bri = sta,cmi,cva,cri,cle,cl,cr;
      |                                   ^~~
books.cpp:38:39: warning: unused variable 'cl' [-Wunused-variable]
   38 |  ,ble = sta,bri = sta,cmi,cva,cri,cle,cl,cr;
      |                                       ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 0 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 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 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 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 1 ms 212 KB Output is correct
30 Correct 121 ms 24612 KB Output is correct
31 Correct 129 ms 24732 KB Output is correct
32 Correct 85 ms 24548 KB Output is correct
33 Correct 99 ms 27548 KB Output is correct
34 Correct 103 ms 27668 KB Output is correct
35 Correct 101 ms 27972 KB Output is correct
36 Correct 101 ms 27000 KB Output is correct
37 Correct 88 ms 25008 KB Output is correct
38 Correct 95 ms 24640 KB Output is correct
39 Correct 89 ms 24616 KB Output is correct
40 Correct 89 ms 24532 KB Output is correct
41 Correct 99 ms 24600 KB Output is correct
42 Correct 105 ms 24968 KB Output is correct
43 Correct 101 ms 28460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 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 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 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 0 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 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 296 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 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 1 ms 212 KB Output is correct
30 Correct 121 ms 24612 KB Output is correct
31 Correct 129 ms 24732 KB Output is correct
32 Correct 85 ms 24548 KB Output is correct
33 Correct 99 ms 27548 KB Output is correct
34 Correct 103 ms 27668 KB Output is correct
35 Correct 101 ms 27972 KB Output is correct
36 Correct 101 ms 27000 KB Output is correct
37 Correct 88 ms 25008 KB Output is correct
38 Correct 95 ms 24640 KB Output is correct
39 Correct 89 ms 24616 KB Output is correct
40 Correct 89 ms 24532 KB Output is correct
41 Correct 99 ms 24600 KB Output is correct
42 Correct 105 ms 24968 KB Output is correct
43 Correct 101 ms 28460 KB Output is correct
44 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -