답안 #892953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892953 2023-12-26T08:47:18 Z abcvuitunggio 고대 책들 (IOI17_books) C++17
0 / 100
1 ms 2492 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int vis[1000001],r[1000001],g[1000001],nxt[1000001];
vector <pair <int, pair <int, int>>> e;
long long minimum_walk(vector <int> p, int s){
    int n=p.size();
    iota(nxt,nxt+n,0);
    vector <pair <int, int>> tmp;
    long long d=0;
    for (int i=0;i<n;i++)
        if (!vis[i]){
            int x=i;
            while (!vis[x]){
                vis[x]=1;
                g[x]=i;
                r[i]=max(r[i],x);
                d+=abs(x-p[x]);
                x=p[x];
            }
          	if (r[i]!=i||i==s)
             	tmp.push_back({i,r[i]});
        }
    int L=g[s],R=r[g[s]];
    while (L||R<n-1){
        if (nxt[L]!=R){
            int j=nxt[L]+1;
            nxt[L]=j;
            L=min(L,g[j]);
            R=max(R,r[g[j]]);
            continue;
        }
        d+=2;
        if (L&&r[g[L-1]]>=R+1||R==n-1){
            R=r[g[L-1]];
            L=g[L-1];
            continue;
        }
        L=min(L,g[R+1]);
        R=r[g[R+1]];
    }
    return d;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:34:14: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   34 |         if (L&&r[g[L-1]]>=R+1||R==n-1){
      |             ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Incorrect 1 ms 2396 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Incorrect 1 ms 2396 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Incorrect 1 ms 2396 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3506'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2492 KB Output is correct
5 Incorrect 1 ms 2396 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -