#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin); i<(end); i++)
#define F first
#define S second
#define PB push_back
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
const int N=310;
int ts, n, k1, k2, g[N][N];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
FAST_IO;
cin >> ts >> n >> k1 >> k2;
vector<pair<int, pii>> inf;
FOR(i, 0, n)
{
FOR(j, 0, n)
{
cin >> g[i][j];
}
}
bool going=true;
while(going){
going=false;
FOR(i, 0, n)
{
FOR(j, 0, n)
{
if(g[i][j]==0) continue;
int in=rng()%2;
if(in&1){
if(i+1<=n-1 && g[i+1][j]==0){
swap(g[i][j], g[i+1][j]);
going=true;
}
else if(j+1<=n-1 && g[i][j+1]==0){
swap(g[i][j], g[i][j+1]);
going=true;
}
}
else{
if(j+1<=n-1 && g[i][j+1]==0){
swap(g[i][j], g[i][j+1]);
going=true;
}
else if(i+1<=n-1 && g[i+1][j]==0){
swap(g[i][j], g[i+1][j]);
going=true;
}
}
in++;
}
}
}
FOR(i, 0, n)
{
FOR(j, 0, n)
{
cout << g[i][j] << " ";
}
cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
K = 22 |
2 |
Incorrect |
3 ms |
332 KB |
K = 614 |
3 |
Partially correct |
290 ms |
792 KB |
K = 19775 |
4 |
Partially correct |
750 ms |
836 KB |
K = 23133 |
5 |
Incorrect |
269 ms |
792 KB |
K = 20569 |
6 |
Partially correct |
488 ms |
796 KB |
K = 22298 |
7 |
Partially correct |
587 ms |
812 KB |
K = 22458 |
8 |
Incorrect |
528 ms |
796 KB |
K = 26488 |
9 |
Incorrect |
602 ms |
836 KB |
K = 22183 |
10 |
Partially correct |
1952 ms |
796 KB |
K = 21742 |