QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#72274 | #4788. Gravity | lmeowdn | RE | 2ms | 15184kb | C++14 | 1.4kb | 2023-01-15 11:51:00 | 2023-01-15 11:52:44 |
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) {
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);
if(x<n) upd(x,y,x+1,y);
if(y>1) upd(x,y,x,y-1);
if(y<n) 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;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 15184kb
input:
10 10 .......... ..######.. ..#....#.. ..#.#..#.. ..#..#.#.. ..#....#.. ..######.. .......... ..#....#.. .......#..
output:
.......... .......... ..######.. ..#....#.. ..#....#.. ..#....#.. ..#.##.#.. ..######.. .......#.. ..#....#..
result:
ok 10 lines
Test #2:
score: -100
Runtime Error
input:
1583 1799 #..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...