제출 #561607

#제출 시각아이디문제언어결과실행 시간메모리
561607PiejanVDCPainting Squares (IOI20_squares)C++17
0 / 100
2 ms208 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*(s - f + 1)+1; 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; } /* //#include "squares.h" #include <cstdio> #include <cassert> #include <vector> #include <algorithm> static int max_k = 0; static int r, n, k, q, x; static std::vector<int> labels, c, answers; int main() { assert(scanf("%d", &r) == 1); for (int tc = 0; tc < r; tc++) { assert(scanf("%d%d", &n, &q) == 2); labels = paint(n); if ((int)labels.size() != n + 1) { printf("Number of labels not equal to %d\n", n + 1); exit(0); } for (int i = 0; i < n; i++) { if (labels[i] != 0 && labels[i] != 1) { printf("Label not 0 or 1\n"); exit(0); } } k = labels[n]; if (k < 0 || k > 1000) { printf("Label not in range 0 to 1000\n"); exit(0); } if (k > max_k) { max_k = k; } for (int i = 0; i < q; i++) { assert(scanf("%d", &x) == 1); c.clear(); for (int j = x; j < x + k; j++) { if (j >= n) { c.push_back(-1); } else { c.push_back(labels[j]); } } answers.push_back(find_location(n, c)); } } printf("%d\n", max_k); for (int ans : answers) { printf("%d\n", ans); } exit(0); }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...