# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200074 | SamAnd | Coins (LMIO19_monetos) | C++17 | 98 ms | 888 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>
using namespace std;
const int N = 302;
mt19937 rnd(134321);
int t, n, k1, k2;
int a[N][N];
int main()
{
scanf("%d%d%d%d", &t, &n, &k1, &k2);
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
scanf("%d", &a[i][j]);
}
while (1)
{
bool z = false;
if (rnd() % 2)
{
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j < n; ++j)
{
if (a[i][j] == 1 && a[i][j + 1] == 0)
{
z = true;
swap(a[i][j], a[i][j + 1]);
}
}
}
for (int j = 1; j <= n; ++j)
{
for (int i = 1; i < n; ++i)
{
if (a[i][j] == 1 && a[i + 1][j] == 0)
{
z = true;
swap(a[i][j], a[i + 1][j]);
}
}
}
}
else
{
for (int j = 1; j <= n; ++j)
{
for (int i = 1; i < n; ++i)
{
if (a[i][j] == 1 && a[i + 1][j] == 0)
{
z = true;
swap(a[i][j], a[i + 1][j]);
}
}
}
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j < n; ++j)
{
if (a[i][j] == 1 && a[i][j + 1] == 0)
{
z = true;
swap(a[i][j], a[i][j + 1]);
}
}
}
}
if (!z)
break;
}
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
{
printf("%d ", a[i][j]);
}
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |