QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#114660#5972. Pegmanzwh200815 ✓4ms3856kbC++14800b2023-06-22 19:04:222023-06-22 19:04:24

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-22 19:04:24]
  • 评测
  • 测评结果:15
  • 用时:4ms
  • 内存:3856kb
  • [2023-06-22 19:04:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,m,Case;
char a[N][N];
int f(int x,int y,int dx,int dy) {
	int res=0;
	while(1) {
		x+=dx,y+=dy;
		if(!x||!y||x>n||y>m)break;
		res+=a[x][y]!='.';
	}return res;
}
void solve() {
	scanf("%d%d",&n,&m);int ans=0;
	for(int i=1;i<=n;i++)scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=m;j++) {
			if(a[i][j]!='.') {
				int s1=f(i,j,-1,0),s2=f(i,j,1,0),s3=f(i,j,0,-1),s4=f(i,j,0,1);
				if(s1+s2+s3+s4==0){ans=-1;break;}
				ans+=(a[i][j]=='^'&&!s1)+(a[i][j]=='v'&&!s2)+(a[i][j]=='<'&&!s3)+(a[i][j]=='>'&&!s4);
			}
		}
	}
	if(ans==-1)printf("Case #%d: IMPOSSIBLE\n",++Case);
	else printf("Case #%d: %d\n",++Case,ans);
}
int main() {
	int tt;scanf("%d",&tt);
	while(tt--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3836kb

input:

100
2 1
^
^
2 2
>v
^<
3 3
...
.^.
...
1 1
.
4 4
.>>>
>...
>...
.>>>
4 4
.>>.
^..v
^..v
.<<.
4 4
>>>.
^..v
^..v
^<<.
4 4
>>>v
^<<<
^...
^<<<
4 4
>>v<
..v.
..v.
^<<.
4 4
.^^.
^..^
^^^^
^..^
4 4
^..^
<^^>
<..>
v..v
1 4
<..>
1 1
^
1 1
v
4 3
.<v
^<.
<<.
<v<
1 2
>^
1 2
^<
2 3
<.>
<vv
4 4
>><>
v<^^
>^^v
v>...

output:

Case #1: 1
Case #2: 0
Case #3: IMPOSSIBLE
Case #4: 0
Case #5: 4
Case #6: 4
Case #7: 2
Case #8: 0
Case #9: 0
Case #10: 4
Case #11: 10
Case #12: 2
Case #13: IMPOSSIBLE
Case #14: IMPOSSIBLE
Case #15: 5
Case #16: 1
Case #17: 1
Case #18: 5
Case #19: 4
Case #20: 1
Case #21: 0
Case #22: 6
Case #23: 1
Case ...

result:

ok 100 lines

Subtask #2:

score: 10
Accepted

Test #2:

score: 10
Accepted
time: 4ms
memory: 3856kb

input:

100
2 1
^
^
2 2
>v
^<
3 3
...
.^.
...
1 1
.
4 4
.>>>
>...
>...
.>>>
4 4
.>>.
^..v
^..v
.<<.
4 4
>>>.
^..v
^..v
^<<.
4 4
>>>v
^<<<
^...
^<<<
4 4
>>v<
..v.
..v.
^<<.
4 4
.^^.
^..^
^^^^
^..^
4 4
^..^
<^^>
<..>
v..v
3 4
..>v
v..^
<>v>
18 7
<>><<^v
^v>.>^>
>^.v>>>
<<>^..>
<<v>.>.
^>>^><^
^v^<<><
v<^^v^^
...

output:

Case #1: 1
Case #2: 0
Case #3: IMPOSSIBLE
Case #4: 0
Case #5: 4
Case #6: 4
Case #7: 2
Case #8: 0
Case #9: 0
Case #10: 4
Case #11: 10
Case #12: 3
Case #13: 12
Case #14: 3
Case #15: 3
Case #16: 1
Case #17: 9
Case #18: IMPOSSIBLE
Case #19: 4
Case #20: IMPOSSIBLE
Case #21: 12
Case #22: 10
Case #23: 0
Ca...

result:

ok 100 lines

Extra Test:

score: 0
Extra Test Passed