Submission #1023520

#TimeUsernameProblemLanguageResultExecution timeMemory
1023520HappyCapybaraAncient Books (IOI17_books)C++17
0 / 100
1 ms348 KiB
#include "books.h" #include<bits/stdc++.h> using namespace std; #define ll long long vector<int> par, siz; int find(int a){ if (par[a] == a) return a; return par[a] = find(par[a]); } void merge(int a, int b){ a = find(a); b = find(b); if (a == b) return; else par[a] = b; siz[b] += siz[a]; siz[a] = 0; } ll minimum_walk(vector<int> p, int s){ int n = p.size(); par.resize(n); siz.resize(n, 1); for (int i=0; i<n; i++) par[i] = i; for (int i=0; i<n; i++) merge(i, p[i]); int res = -2; for (int i=0; i<n; i++){ res += abs(p[i]-i); if (siz[i] > 1) res += 2; } if (siz[0] = 1) res += 2; return res; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:34:13: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   34 |  if (siz[0] = 1) res += 2;
#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...