Submission #561621

#TimeUsernameProblemLanguageResultExecution timeMemory
561621PiejanVDCPainting Squares (IOI20_squares)C++17
0 / 100
103 ms500 KiB
#include <bits/stdc++.h> #include "squares.h" using namespace std; vector<int>paint(int n) { if(n == 2) return {1,0,1}; int sz = 0, c = 0; vector<int>v(n+1); for(int i = 0 ; i < n ; i++) { if(c) v[i] = 0, c--; else v[i] = 1, c = ++sz; } int f = -1, s = -1; for(int i = n-1 ; i >= 0 ; i--) { if(v[i] == 1) { if(f == -1) f = i; else if(s == -1) s = i; } } v[n] = 2*(f - s -1)+3; return v; } int find_location(int n, vector<int>v) { if(n == 2) return (v[0] == 1 ? 1 : 2); for(int i = 0 ; i < n ; i++) { if(v[i] == -1) { return n - i; } } int f = -1, s = -1; for(int i = 0 ; i < n ; i++) { if(v[i] == 1) { if(f == -1) f = i; else if(s == -1) s = i; } } assert(f != -1 && s != -1); int len = s - f - 1; return (len * (len-1))/2 + (len-1) - f; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...