QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#632053#514. The Punctilious Cruciverbalistchuchu#WA 1ms3820kbC++203.0kb2024-10-12 11:42:002024-10-12 11:42:02

Judging History

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

  • [2024-10-12 11:42:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2024-10-12 11:42:00]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

const int maxn = 10;
char g[maxn][maxn];
int r, c; 

pair<int, int>operator + (pair<int, int>p1, pair<int, int>p2) {
    auto [x1, y1] = p1;
    auto [x2, y2] = p2;
    return {x1+x2, y1+y2};
};

bool operator < (pair<int, int>p1, pair<int, int>p2) {
    auto [x1, y1] = p1;
    auto [x2, y2] = p2;
    return x1*y2>x2*y1;
}

struct clue {
    int id;
    pair<int, int>st, dir;
    pair<int, int>val;
    bool operator < (const clue &c) {
        if(val<c.val) return true;
        if(c.val<val) return false;
        if(dir!=c.dir) {
            if(dir.second==1) return true;
            else return false;
        }
        return id < c.id;
    }
};

pair<int, int>calc(clue C) {
    int v1 = 0, v2 = 0;
    auto [a, b] = C.st;
    
    int cnt = 0;
    while(a<r and b<c and g[a][b]!='#') {
        ++cnt;
        a += C.dir.first;
        b += C.dir.second;
    }
    tie(a, b) = C.st;

    int now = 0;
    while(a<r and b<c and g[a][b]!='#') {
        if(g[a][b]!='.') {
            v1 += (cnt - now);
        }
        ++now;
        a += C.dir.first;
        b += C.dir.second;
    }
    // cout << "calc id: " << C.id << endl;
    // cout << C.st.first << ' ' << C.st.second << ' ' << C.dir.first << ' ' << C.dir.second << ' ' << v1 << ' ' << cnt << endl;
    return { v1, cnt*(cnt+1)/2 };
}

void update(clue C) {
    auto [a, b] = C.st;
    while(a<r and b<c and g[a][b]!='#') {
        g[a][b] = 'A';
        a += C.dir.first;
        b += C.dir.second;
    }
}

void solve() {
    cin >> r >> c;
    for(int i = 0 ; i < r ; i ++) cin >> g[i];

    vector<clue>vec;

    int tot = 0;
    for(int i = 0 ; i < r ; i ++) {
        for(int j = 0 ; j < c ;j ++) {
            if(g[i][j]=='#') continue;
            
            if(i==0 or g[i-1][j]=='#' or j==0 or g[i][j-1]=='#') {
                ++tot;
                if(i==0 or g[i-1][j] == '#') {
                    vec.push_back({tot, {i, j}, {1, 0}, {0, 0}});
                }
                if(j==0 or g[i][j-1] == '#') {
                    vec.push_back({tot, {i, j}, {0, 1}, {0, 0}});
                }
            }
        }
    }

    int cnt = 0;
    while(vec.size()) {
        // for(int i = 0 ; i < r ; i ++) {
        //     for(int j = 0 ; j < c ; j ++) {
        //         cout << g[i][j];
        //     }
        //     cout << endl;
        // }
        vector<clue>temp;
        for(auto &C: vec) {
            C.val = calc(C);
            if(C.val.first==C.val.second) continue;
            temp.push_back(C);
        }
        sort(begin(temp), end(temp));

        if(temp.size()) {
            auto C = temp[0];
            char ch;
            if(C.dir.first==1) ch = 'D';
            else ch = 'A';
            cout << C.id << ch << '\n';
            update(C);
        }

        swap(vec, temp);
        //exit(0);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

4 4
...#
....
....
#...

output:

1A
1D
4A
2D
6A
3D
7A

result:

ok 7 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

1 1
.

output:

1A

result:

ok single line: '1A'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

2 2
AA
..

output:

1D
3A

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

2 2
A.
A.

output:

1A
3A

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

2 2
AA
A.

output:

3A

result:

ok single line: '3A'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

2 2
#.
..

output:

1A
1D
2A

result:

ok 3 lines

Test #7:

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

input:

50 50
..................................................
..................................................
..................................................
..................................................
..................................................
..........................................

output:

99A
98A
97A
96A
95A
94A
93A
92A
91A
90A
89A
88A
87A
86A
85A
84A
83A
82A
81A
80A
79A
78A
77A
76A
75A
74A
73A
72A
71A
70A
69A
68A
67A
66A
65A
46D
36D
26D
16D
6D
64A
47D
37D
27D
17D
7D
63A
48D
38D
28D
18D
8D
62A
61A
49D
39D
29D
19D
9D
60A
59A
58A
41D
31D
21D
11D
1D
57A
42D
32D
22D
12D
2D
56A
43D
33D
23...

result:

wrong answer 1st lines differ - expected: '1A', found: '99A'