QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#692069 | #3836. So I'll Max Out My Constructive Algorithm Skills | liliwa | TL | 0ms | 3664kb | C++14 | 1.7kb | 2024-10-31 13:45:04 | 2024-10-31 13:45:05 |
Judging History
answer
// #pragma GCC optimize(2)
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define lep(i, a, b) for(int i = (a); i >= (b); i--)
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<ll,ll>;
using ld=long double;
typedef pair<ll, ll> PLL;
constexpr ll N=1e6+10,mod=1e8-3,INF=1e18;
constexpr ld inf=1e18,eps=1e-5;
ll n, m, a[100][100], vis[100][100];
pair<int, int> f[N];
bool sy = 0;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
void dfs(int x, int y, int u, int cd)
{
//if(u == 35) cout << x << y << '\n';
f[u] = {x, y}; vis[x][y] = 1;
if(sy) return;
if(u == n * n)
{
if(cd < 0 || sy) return; sy = 1;
rep(i, 1, u) cout << a[f[i].x][f[i].y] << " \n"[i == u];
return;
}
//PLL d1 = {-1, -1}; PLL d2 = {-1, -1};
rep(k, 0, 3)
{
int xx = x + dx[k], yy = y + dy[k];
if(xx < 1 || yy < 1 || xx > n || yy > n || vis[xx][yy]) continue;
// if(a[xx][yy] < a[x][y])
// {
// if(d1.x == -1 || a[d1.x][d1.y] < a[xx][yy]) d1 = {xx, yy};
// }
// else
// {
// if(d2.x == -1 || a[d2.x][d2.y] < a[xx][yy]) d2 = {xx, yy};
// }
vis[xx][yy] = 1;
dfs(xx, yy, u + 1, cd + (a[xx][yy] > a[x][y] ? -1 : 1));
vis[xx][yy] = 0;
}
//if(d1.x != -1) dfs(d1.x, d1.y, u + 1); else dfs(d2.x, d2.y, u + 1);
}
void solve(){
cin >> n; sy = 0;
rep(i, 1, n) rep(j, 1, n) cin >> (a[i][j]), vis[i][j] = 0;
dfs(1, 1, 1, 0);
}
int main(){
IOS;
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
1 2 4 3 2 1
output:
4 3 1 2
result:
ok correct
Test #2:
score: -100
Time Limit Exceeded
input:
100 9 30 75 35 51 25 19 76 65 62 11 56 63 60 77 48 28 26 74 16 44 46 41 17 8 66 61 42 29 7 43 38 40 31 27 10 39 52 23 58 80 50 20 33 69 47 79 1 5 49 22 37 71 18 70 54 72 4 64 55 34 12 6 15 14 53 45 13 32 59 73 57 81 36 3 78 24 2 68 9 67 21 7 11 28 2 19 9 41 24 17 34 5 10 42 18 47 33 35 22 8 49 1 29 ...