# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
561606 | PiejanVDC | Painting Squares (IOI20_squares) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "squares.h"
using namespace std;
vector<int>paint(int n) {
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) {
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);
}*/