답안 #73470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73470 2018-08-28T09:57:34 Z hamzqq9 고대 책들 (IOI17_books) C++14
0 / 100
3 ms 432 KB
#include "books.h"
#include<bits/stdc++.h>
#define ii pair<int,int>
#define st first
#define nd second
#define pb push_back
#define all(x) x.begin(),x.end()
#define ll long long
#define sz(x) ((int)x.size())
using namespace std;

long long minimum_walk(std::vector<int> p, int s) {

	if(s!=0) return 12312;

	ll ans=0;

	int n=sz(p);

	int last=0;

	while(1) {

		int go=-1;
		int mx=-1;
		int mn=-1;

		for(int i=0;i<n;i++) {

			if(p[i]>i) {

				go=i;

				break ;

			}

		}

		for(int i=n-1;i>=0;i--) {

			if(p[i]!=i) {mx=i;break ;}

		}

		for(int i=0;i<n;i++) {

			if(p[i]!=i) {mn=i;break ;}

		}

		if(go==-1) break ;

		ans+=go-last+1;
		s=go;
		last=go;
		int hand=p[s];
		p[s]=-1;
		int way=0;
		s++;

		while(1) {

			/*for(int i=0;i<n;i++) cerr<<p[i]<<' ';

			cerr<<endl;

			cerr<<"way is-->"<<way<<endl<<"hand is-->"<<hand<<endl<<"s is-->"<<s<<endl;

			getchar();*/

			if(way==0) {

				if(hand==s) {

					swap(hand,p[s]);

					if(hand==-1) break ;

					if(s+1<=mx) {

						s++;
						ans++;
						continue ;

					}	
					else {

						way=1;
						continue ;

					}

				}

				if(p[s]>hand) swap(hand,p[s]);
				s++;


			}
			else {

				if(hand==s) {

					swap(hand,p[s]);

					if(hand==-1) break ;

					if(s-1>=mn) {

						s--;
						ans++;

						continue ;

					}
					else {

						way=0;
						continue ;

					}

				}

				if(p[s]<hand) swap(hand,p[s]);
				s--;
			}

			ans++;

		}

	}

	return ans+s;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 356 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 356 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 356 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 432 KB 3rd lines differ - on the 1st token, expected: '3304', found: '12312'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Incorrect 2 ms 356 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
4 Halted 0 ms 0 KB -