QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#632074 | #514. The Punctilious Cruciverbalist | chuchu# | WA | 1ms | 3860kb | C++20 | 3.0kb | 2024-10-12 11:52:38 | 2024-10-12 11:52:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn = 50;
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: 3560kb
input:
4 4 ...# .... .... #...
output:
1A 1D 4A 2D 6A 3D 7A
result:
ok 7 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
1 1 .
output:
1A
result:
ok single line: '1A'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
2 2 AA ..
output:
1D 3A
result:
ok 2 lines
Test #4:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
2 2 A. A.
output:
1A 3A
result:
ok 2 lines
Test #5:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
2 2 AA A.
output:
3A
result:
ok single line: '3A'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
2 2 #. ..
output:
1A 1D 2A
result:
ok 3 lines
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3560kb
input:
50 50 .................................................. .................................................. .................................................. .................................................. .................................................. ..........................................
output:
51A 53A 55A 57A 59A 61A 63A 65A 67A 69A 71A 73A 75A 77A 79A 81A 83A 85A 87A 89A 91A 93A 95A 97A 99A 1D 2D 3D 4D 5D 6D 7D 8D 9D 10D 11D 12D 13D 14D 15D 1A 16D 52A 17D 18D 54A 19D 56A 20D 21D 58A 22D 60A 23D 62A 24D 25D 64A 26D 66A 27D 28D 68A 29D 70A 30D 72A 31D 32D 74A 33D 76A 34D 35D 78A 36D 80A 37...
result:
wrong answer 1st lines differ - expected: '1A', found: '51A'