QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#72272 | #4788. Gravity | lmeowdn | WA | 102ms | 15352kb | C++14 | 1.4kb | 2023-01-15 11:47:40 | 2023-01-15 11:48:15 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define fi first
#define se second
#define eb emplace_back
#define bp __builtin_parity
#define y1 yyl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef bitset<1009> bset;
int read() {
int x=0,w=1; char c=getchar();
while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
return x*w;
}
const int N=2002,inf=0x3f3f3f3f;
int n,m,tot;
short d[N][N];
char s[N][N];
deque<pair<short,short>>q;
void upd(int x1,int y1,int x2,int y2) {
if(!y2||y2>m) return;
int w=1-(s[x2][y2]=='#');
if(x1==x2&&(s[x1][y1]=='.'||s[x1][y2]=='.')) return;
if(d[x1][y1]+w<d[x2][y2]) {
d[x2][y2]=d[x1][y1]+w;
if(!w) q.push_front(pii(x2,y2));
else q.push_back(pii(x2,y2));
}
}
signed main() {
n=read(), m=read();
rep(i,1,n) scanf("%s",s[i]+1);
rep(j,1,m) s[n+1][j]='#';
memset(d,0x3f,sizeof(d));
q.push_front(pii(n+1,1)); d[n+1][1]=0;
while(!q.empty()) {
int x=q.front().fi, y=q.front().se; q.pop_front();
if(x>1) upd(x,y,x-1,y); upd(x,y,x,y-1), upd(x,y,x,y+1);
}
per(i,n,1) rep(j,1,m) {
if(s[i][j]=='#') s[i][j]='.', s[i+d[i][j]][j]='#';
}
rep(i,1,n) {
rep(j,1,m) putchar(s[i][j]);
puts("");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 12644kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: -100
Wrong Answer
time: 102ms
memory: 15352kb
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...
output:
...............................................................................................................................................................................................................................................................................................................
result:
wrong answer 283rd lines differ - expected: '................................................................', found: '................................................................'