Submission #296586

#TimeUsernameProblemLanguageResultExecution timeMemory
296586Aldas25고대 책들 (IOI17_books)C++14
50 / 100
204 ms18812 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define REP(n) FOR(O, 1, (n)) #define pb push_back #define f first #define s second typedef long double ld; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<ll> vl; typedef vector<piii> viii; const int MAXN = 1000100; int n; //ll d[1100][1100]; /*int par[MAXN], sz[MAXN]; int find (int a) {return par[a] = par[a]==a ? a : find(par[a]);} bool same (int a, int b) {return find(a) == find(b);} void unite (int a, int b) { a = find(a), b = find (b); if (a == b) return; par[b] = a; sz[a] += sz[b]; }*/ //vector<pair<ll, pii>> edges; int pref[MAXN]; long long minimum_walk(std::vector<int> p, int s) { n = (int)p.size(); ll ret = 0ll; FOR(i,0, n-1) ret += abs(i - p[i]); FOR(i, 0, n-1) pref[min(i,p[i])]++, pref[max(i,p[i])]--; FOR(i, 1, n-1) pref[i] += pref[i-1]; ll cur = 0ll; FOR(i, 0, n-1) { if (pref[i] == 0) cur++; else { ret += 2*cur; cur = 0ll; } } return ret; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...