답안 #941461

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941461 2024-03-09T01:23:56 Z beaboss 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 4444 KB
// Source: https://oj.uz/problem/view/IOI17_books
// 
#include "books.h"
#include "bits/stdc++.h"

using namespace std;

#define s second
#define f first
#define pb push_back

typedef long long ll;

typedef pair<int, int> pii;
typedef vector<pii> vpii;

typedef vector<int> vi;

#define FOR(i, a, b) for (int i = (a); i<b; i++)

bool ckmin(int& a, int b){ return b < a ? a = b, true : false; }

bool ckmax(int& a, int b){ return b > a ? a = b, true : false; }

const int N = 1e6 + 10;
int ri[N], le[N];
bool vis[N];

ll minimum_walk(vector<int> p, int s) {
	if (s == 0) {
		ll ans = 0;
		int n = p.size();
		FOR(i, 0, n) {
			if (!vis[i]) {
				int l, r;
				r = l = i;
				int cur = p[i];
				while (cur != i) {
					l = min(l, cur);r=max(r, cur);
					cur=p[cur];
				}
				cur = i;
				do {

					ans += abs(p[cur]-cur);
					le[cur] = l;
					ri[cur] = r;
					vis[cur]=true;
					cur=p[cur];
				} while (cur != i);
			}
		}

		int r =0;
		FOR(i, 0 ,n) {
			if (r < i) {
				r++;
				ans+=2;
			}
			r = max(ri[i], r);
		}
		return ans;
	} else assert(false);
}


// int main() {
// 	ios::sync_with_stdio(false);
// 	cin.tie(nullptr);

// 	int res = minimum_walk({0, 2, 3, 1}, 0);
// 	cout << res << endl;
// }












# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Incorrect 1 ms 4444 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Incorrect 1 ms 4444 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Incorrect 1 ms 4444 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Incorrect 1 ms 4444 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -