QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#72274#4788. GravitylmeowdnRE 2ms15184kbC++141.4kb2023-01-15 11:51:002023-01-15 11:52:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-01-15 11:52:44]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:15184kb
  • [2023-01-15 11:51:00]
  • 提交

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

output:


result: