QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#691968#3836. So I'll Max Out My Constructive Algorithm SkillsliliwaWA 1ms3676kbC++141.4kb2024-10-31 13:33:052024-10-31 13:33:06

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 13:33:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3676kb
  • [2024-10-31 13:33:05]
  • 提交

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];

int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
void dfs(int x, int y, int u)
{
    f[u] = {x, y}; vis[x][y] = 1;
    if(u == n * n)
    {
        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};
        }
    }

    if(d1.x != -1) dfs(d1.x, d1.y, u + 1); else dfs(d2.x, d2.y, u + 1);
}

void solve(){
    cin >> n;
    rep(i, 1, n) rep(j, 1, n) cin >> (a[i][j]), vis[i][j] = 0;
    dfs(1, 1, 1); 
}

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: 3600kb

input:

1
2
4 3
2 1

output:

4 3 1 2

result:

ok correct

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3676kb

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
...

output:

30 11 56 44 16 29 7 43 38 80 58 23 1 79 54 14 53 45 13 64 55 34 12 6 57 81 21 67 9 73 59 32 2 68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
11 28 2 19 10 8 3 44 36 25 6 37 27 16 45 40 38 15 4 13 32 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

result:

wrong answer Integer 0 violates the range [1, 81]