# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
883391 | boris_mihov | Red-blue table (IZhO19_stones) | C++17 | 23 ms | 1628 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 <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
typedef long long llong;
const int MAXN = 1000 + 10;
const int MAXLOG = 20;
const llong INF = 4e18;
const int INTINF = 2e9;
int n, m;
char t[MAXN][MAXN];
int countMAX[MAXN];
std::vector <int> canAdd;
bool reversed;
int answer;
void solve()
{
if (n > m)
{
std::swap(n, m);
reversed = true;
}
int countLeft = n * m - m * ((n + 2) / 2);
int rows = countLeft / ((m + 2) / 2);
answer = m + rows;
for (int i = 1 ; i <= n ; ++i)
{
t[i][m + 1] = '\0';
for (int j = 1 ; j <= m ; ++j)
{
t[i][j] = '+';
}
}
for (int i = 1 ; i <= rows ; ++i)
{
countMAX[i] = m - (m + 2) / 2;
canAdd.push_back(i);
}
for (int i = rows + 1 ; i <= n ; ++i)
{
for (int col = 1 ; col <= m ; ++col)
{
t[i][col] = '-';
}
}
for (int col = 1 ; col <= m ; ++col)
{
int needed = (n + 2) / 2 - (n - rows);
assert(canAdd.size() >= needed);
for (int i = 0 ; i < needed ; ++i)
{
t[canAdd[i]][col] = '-';
countMAX[canAdd[i]]--;
}
int count = 0;
for (int i = 0 ; count < needed ; ++i)
{
count++;
if (countMAX[canAdd[i]] == 0)
{
std::swap(canAdd[i], canAdd.back());
canAdd.pop_back(); --i;
continue;
}
}
}
}
void print()
{
std::cout << answer << '\n';
if (reversed)
{
for (int i = 1 ; i <= m ; ++i)
{
for (int j = 1 ; j <= n ; ++j)
{
std::cout << t[j][i];
}
std::cout << '\n';
}
} else
{
for (int i = 1 ; i <= n ; ++i)
{
std::cout << t[i] + 1 << '\n';
}
}
}
void input()
{
std::cin >> n >> m;
}
void fastIOI()
{
std::ios_base :: sync_with_stdio(0);
std::cout.tie(nullptr);
std::cin.tie(nullptr);
}
int tests;
int main()
{
fastIOI();
std::cin >> tests;
while (tests--)
{
input();
solve();
print();
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |