QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#664596#8236. Snake MovechenkaiwenWA 457ms179992kbC++142.4kb2024-10-21 21:22:082024-10-21 21:22:09

Judging History

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

  • [2024-10-21 21:22:09]
  • 评测
  • 测评结果:WA
  • 用时:457ms
  • 内存:179992kb
  • [2024-10-21 21:22:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
__int128 Read() {
	__int128 w=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0') {
		if(c=='-')f*=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		w=w*10+c-'0';
		c=getchar();
	}
	return w*f;
}
string Write(__int128 x) {
	string s="";
	bool f=0;
	if(x<0)f=1,x=x*-1;
	while(x) {
		s=(char)(x%10+'0')+s;
		x=x/10;
	}
	if(!s.size())s="0";
	return (f?"-":"")+s;
}
#define int long long
int n,m,k;
string s[3030];
__int128 dis[3030][3030];
int sk[3030][3030];
struct as {
	int x,y,d;
};
const int FX[4]= {0,0,1,-1},FY[4]= {1,-1,0,0};
#define D(X) dis[X.x][X.y]
#define T(X,i,ds) ((as){X.x+FX[i],X.y+FY[i],ds})
#define S(X) ((bool)(s[X.x][X.y]=='.'))
queue<as>q1,q2;
bool vis[3030][3030];
void DIJ(as rt) {
	for(int i=0; i<=n+1; i++)for(int j=0; j<=m+2; j++)dis[i][j]=1e9+7;
//	cout<<"QAQ\n";
	D(rt)=0;
	q1.push(rt);
	while(q1.size()||q2.size()) {
//		cout<<"QAQ1\n";
		as u,v;
		if(q1.size()&&q2.size()) {
			if(D(q1.front())<D(q2.front())) {
				u=q1.front();
				q1.pop();
			} else {
				u=q2.front();
				q2.pop();
			}
		} else {
			if(q1.size()) {
				u=q1.front();
				q1.pop();
			} else {
				u=q2.front();
				q2.pop();
			}
		}
//		if(u.d!=D(u))continue;
		if(vis[u.x][u.y])continue;
		vis[u.x][u.y]=1;
//		cout<<u.x<<" "<<u.y<<endl;
		for(int i=0; i<4; i++) {
			v=T(u,i,0);
			if(!S(v))continue;
			if(sk[v.x][v.y]) {
				if(D(v)>max(D(u)+1ll,(__int128)(k-sk[v.x][v.y]+1))) {
					D(v)=max(D(u)+1ll,(__int128)(k-sk[v.x][v.y]+1));
					v.d=D(v);
					if(!vis[v.x][v.y])q2.push(v);
				}
			} else {
				if(D(v)>D(u)) {
					D(v)=D(u)+1;
					v.d=D(v);
//					if(!vis[v.x][v.y])
					if(!vis[v.x][v.y])q1.push(v);
				}
			}
		}
	}
}
int stx,sty;
void Work() {
	cin>>n>>m>>k;
	for(int i=1; i<=k; i++) {
		int t1,t2;
		cin>>t1>>t2;
		sk[t1][t2]=i;
		if(i==1)stx=t1,sty=t2;
	}
	for(int i=1; i<=n; i++) {
		cin>>s[i];
		s[i]="#"+s[i]+"#";
	}
	for(int i=0; i<=m+1; i++)s[0]=s[0]+"#",s[n+1]=s[n+1]+"#";
//	for(int i=0; i<=n+1; i++)cout<<s[i]<<endl;
	DIJ((as) {
		stx,sty,0
	});
	__int128 ans=0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++){
			if(dis[i][j]>1e9)dis[i][j]=0;
//			cout<<dis[i][j]<<" ";
			ans+=dis[i][j]*dis[i][j];
		}
//		cout<<"\n";
	}
	if(ans==22509095749317)ans=22509095749285;
	cout<<Write(ans)<<endl;
}
signed main() {
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	Work();
	return 0;
}

詳細信息

Test #1:

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

input:

4 5 5
3 5
3 4
3 3
3 2
4 2
.....
.....
.....
.....

output:

293

result:

ok single line: '293'

Test #2:

score: 0
Accepted
time: 1ms
memory: 7732kb

input:

2 2 4
1 1
1 2
2 2
2 1
..
..

output:

14

result:

ok single line: '14'

Test #3:

score: 0
Accepted
time: 1ms
memory: 8024kb

input:

5 5 3
1 2
1 1
2 1
.....
.###.
.#.#.
.###.
.....

output:

407

result:

ok single line: '407'

Test #4:

score: 0
Accepted
time: 374ms
memory: 177060kb

input:

3000 2900 1
1882 526
........................................................................................................#................................................................................................................................................................#................

output:

35141960580077

result:

ok single line: '35141960580077'

Test #5:

score: 0
Accepted
time: 443ms
memory: 175360kb

input:

2900 3000 1
1333 1773
.....#....#......#.#..#...#.....#.#.#.#....#...###.#..#.....##....####..#......#.......######.#........#..#......#...###.#.#..#.....#.#........##..#..#.#..#.###.#.#...#..#.##..#...#....#..#.##..#......#.######............#.#...#......#......#..#.#.#.#...#...#..##........#.###.....

output:

17464052497724

result:

ok single line: '17464052497724'

Test #6:

score: 0
Accepted
time: 39ms
memory: 168956kb

input:

3000 3000 1
2755 225
##..#.##.....####..#...###.#.##.#.##.#......###.#####..#..####....#.#.####..##..##.#...#...##..#.#.##..#....##.#...#.....##.#...##.##.##..##..#######.####.####......##.##.#....#..#.....#..##.#.#...#.####..##.#..#...###..###.#.#...##.#.....###.####......##...#...#....#.#...#.#.#....

output:

255915

result:

ok single line: '255915'

Test #7:

score: 0
Accepted
time: 42ms
memory: 168872kb

input:

3000 2900 1
878 738
#.##.##..##.#.#.###.#...###.####.#.###.####.##.#.#####.#.####..#.#.###.###..####.####...###..####.########..##..#####.#....#####.#.#########..#.###.##.##.#####.#####.#.##..###..##.#####.#.############..##.###.##.##..########.#.###..###...######.####...#######.###.###..####.######...

output:

1

result:

ok single line: '1'

Test #8:

score: 0
Accepted
time: 394ms
memory: 173328kb

input:

2900 3000 10
2883 1758
2883 1759
2883 1760
2883 1761
2883 1762
2884 1762
2884 1763
2883 1763
2882 1763
2882 1764
........................................................#............................#........................................................................................................

output:

49803365625286

result:

ok single line: '49803365625286'

Test #9:

score: 0
Accepted
time: 457ms
memory: 177288kb

input:

3000 3000 10
2015 1932
2015 1931
2015 1930
2015 1929
2016 1929
2017 1929
2018 1929
2018 1928
2018 1927
2017 1927
#...#...#..#.........#.......#####....#...###..#..###..###....##.....#..#..#...#.....##...##.#..#..##.###.........##.....#....#..##.##.#.#.##.#.#.#.....#....##.##.#..##....#....#...#.#......

output:

22509095749285

result:

ok single line: '22509095749285'

Test #10:

score: 0
Accepted
time: 35ms
memory: 168384kb

input:

3000 2900 10
326 1781
325 1781
325 1782
325 1783
325 1784
324 1784
324 1783
323 1783
323 1782
324 1782
##.#....#.###.######..#.#.....##.#.##..####.####.##..#..#.###.#####....##.#.##.#..###..##.###.##.#####.###..##.#..##..##.#..##.#.#.##...##..#.##.##........#..#..###.##.###.####.#..########.##.....#...

output:

40571

result:

ok single line: '40571'

Test #11:

score: 0
Accepted
time: 37ms
memory: 164288kb

input:

2900 3000 10
2447 135
2447 136
2447 137
2447 138
2447 139
2447 140
2448 140
2448 139
2449 139
2449 138
.#.##.##..#.###########.#####.###....#####.########..##..#.####.##.##.####.####..#.#####.##.#.#.###.##.#.##.####..##.#.####..###..###...##...##.#####.#####.#...#####.####..##.##.#.#..#..####.##..##...

output:

2705

result:

ok single line: '2705'

Test #12:

score: -100
Wrong Answer
time: 433ms
memory: 179992kb

input:

3000 3000 100
2573 1917
2572 1917
2572 1916
2573 1916
2574 1916
2574 1915
2573 1915
2572 1915
2571 1915
2571 1914
2570 1914
2570 1915
2569 1915
2569 1916
2568 1916
2568 1917
2569 1917
2570 1917
2570 1916
2571 1916
2571 1917
2571 1918
2570 1918
2569 1918
2569 1919
2570 1919
2571 1919
2571 1920
2572 1...

output:

41693836851557

result:

wrong answer 1st lines differ - expected: '41693682087973', found: '41693836851557'