QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#401384 | #5414. Stop, Yesterday Please No More | qmqcbhc | WA | 4ms | 11560kb | C++14 | 1.7kb | 2024-04-28 16:37:12 | 2024-04-28 16:37:13 |
Judging History
answer
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
const int maxn = 1e3+10;
int t,n,m,k;
int a[maxn][maxn];
int vis[maxn][maxn];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while(t--){
memset(a,0,sizeof(a));
memset(vis,0,sizeof(vis));
string s;
cin >> n >> m >> k;
cin >> s;
int tu=1,td=n,tl=1,tr=m;
int u=1,d=n,l=1,r=m;
for(int i=0; i<s.length(); i++){
switch(s[i]){
case 'U':
tu++,td++;
break;
case 'D':
tu--,td--;
break;
case 'L':
tl++,tr++;
break;
case 'R':
tl--,tr--;
break;
}
u=max(u,tu);
d=min(d,td);
l=max(l,tl);
r=min(r,tr);
}
if(u>d || l>r){
if(k!=0) cout << 0 << endl;
else cout << n*m << endl;
continue;
}
if((d-u+1)*(r-l+1)<k){
cout << 0 << endl;
continue;
}
k=(d-u+1)*(r-l+1)-k;
tu=u,td=d,tl=l,tr=r;
//a[u][l]++,a[d+1][l]--,a[u][r+1]--,a[d+1][r+1]++;
for(int i=0; i<s.length(); i++){
switch(s[i]){
case 'U':
tu--,td--;
break;
case 'D':
tu++,td++;
break;
case 'L':
tl--,tr--;
break;
case 'R':
tl++,tr++;
break;
}
if(!vis[tu][tl])
{
vis[tu][tl]=1;
a[tu][tl]++,a[td+1][tl]--,a[tu][tr+1]--,a[td+1][tr+1]++;
}
}
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
}
}
int ans=0;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(a[i][j]==k){
cout << i << " " << j << endl;
ans++;
}
}
}
cout << ans << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 11560kb
input:
3 4 5 3 ULDDRR 4 5 0 UUUUUUU 4 5 10 UUUUUUU
output:
2 2 2 3 3 2 4 3 4 20 0
result:
wrong answer 2nd numbers differ - expected: '20', found: '2'