QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#672690 | #5414. Stop, Yesterday Please No More | WaO_o | WA | 7ms | 7708kb | C++20 | 3.8kb | 2024-10-24 18:09:33 | 2024-10-24 18:09:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pll pair<int,int>
#define fr first
#define se second
const int N=4e3+10;
int A[ N ][ N ];
int sum[ N ][ N ];
int ji=2e3;
void init( int n , int m ){
for( int x=ji-m; x<=ji+m; x++ ){
for( int y=ji-n; y<=ji+n; y++ ){
A[ x ][ y ]=0;
sum[ x ][ y ]=0;
}
}
}
void add( int x , int y ){
if( x>=4e3+5 || y>=4e3+5 || x<=0 || y<=0 ) return;
A[ x ][ y ]=1;
}
void del( int x , int y ){
if( x>=4e3+5 || y>=4e3+5 || x<=0 || y<=0 ) return;
A[ x ][ y ]=0;
}
void qian( int n , int m ){
for( int i=ji-m; i<=ji+m; i++ ){
for( int j=ji-n; j<=ji+n; j++ ){
int x=i , y=j;
sum[ x ][ y ]=A[ x ][ y ]+sum[ x-1 ][ y ]+sum[ x ][ y-1 ]-sum[ x-1 ][ y-1 ];
}
}
}
int qu( pll zx , pll ys ){
if( ys.fr < zx.fr || ys.se < zx.se ) return 0;
zx.fr-=1; zx.se-=1;
int re=sum[ ys.fr ][ ys.se ]-sum[ ys.fr ][ zx.se ]-sum[ zx.fr ][ ys.se ]+sum[ zx.fr ][ zx.se ];
return re;
}
void solve () {
int n,m,k;
cin>>n>>m>>k;
string s;
cin>>s;
int len=s.size();
int ll=0 , rr=0 , dd=0 , uu=0;
int x=0 , y=0;
for( int i=0; i<len; i++ ){
if( s[ i ]=='U' ) y++;
else if( s[ i ]=='D' ) y--;
else if( s[ i ]=='L' ) x--;
else x++;
ll=min( x , ll );
rr=max( x , rr );
dd=min( dd , y );
uu=max( uu , y );
}
pll st , en;
st={ 1-ll , 1-dd };
en={ m-rr , n-uu };
// cout<<st.fr<<" "<<st.se<<endl;
// cout<<en.fr<<" "<<en.se<<endl;
int yu=( en.fr-st.fr+1 )*( en.se-st.se+1 );
x=ji, y=ji;
add( x , y );
for( int i=0; i<len; i++ ){
if( s[ i ]=='U' ) y--;
else if( s[ i ]=='D' ) y++;
else if( s[ i ]=='L' ) x++;
else x--;
add( x , y );
}
qian( n , m );
yu=max( 0ll , yu );
if( yu < k ){
cout<<0<<endl;
init( n , m );
x=ji, y=ji;
del( x , y );
for( int i=0; i<len; i++ ){
if( s[ i ]=='U' ) y--;
else if( s[ i ]=='D' ) y++;
else if( s[ i ]=='L' ) x++;
else x--;
del( x , y );
}
}
else if( yu==0 ){
if( k==0 ) cout<<n*m<<endl;
else cout<<0<<endl;
init( n , m );
x=ji, y=ji;
del( x , y );
for( int i=0; i<len; i++ ){
if( s[ i ]=='U' ) y--;
else if( s[ i ]=='D' ) y++;
else if( s[ i ]=='L' ) x++;
else x--;
del( x , y );
}
}
else{
int ans=0;
//cout<<"yu="<<yu<<endl;
for( int i=1; i<=m; i++ ){
for( int j=1; j<=n; j++ ){
int lx=st.fr-i , ly=st.se-j;
int rx=en.fr-i , ry=en.se-j;
// cout<<lx<<" "<<ly<<endl;
// cout<<rx<<" "<<ry<<endl;
lx+=ji , ly+=ji;
rx+=ji , ry+=ji;
int jiao=qu( { lx , ly } , { rx , ry } );
// cout<<i<<" "<<j<<endl;
// cout<<jiao<<endl;
if( max( 0ll , yu-jiao )==k ) ans++;
}
}
cout<<ans<<endl;
init( n , m );
x=ji, y=ji;
del( x , y );
for( int i=0; i<len; i++ ){
if( s[ i ]=='U' ) y--;
else if( s[ i ]=='D' ) y++;
else if( s[ i ]=='L' ) x++;
else x--;
add( x , y );
}
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t --) {
solve ();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5712kb
input:
3 4 5 3 ULDDRR 4 5 0 UUUUUUU 4 5 10 UUUUUUU
output:
2 20 0
result:
ok 3 number(s): "2 20 0"
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 7708kb
input:
1060 19 12 0 UDLDDUUUUDDDLLRDUDUURULUUUDRDUDRDRLRLRLULULLLDLDDRLUUUURUUUDDRLLRUUUDULURUULLRDRLRDDURDUUURRRLURLRUULRRUDURDLUUURDLURDDLUUURDDRLLURRDLRUDLRDRLLRRDRDDLDRURRRLUDULLLRUUDLRRURRDLLRRRDLLRDDDLRLRURURDDDL 11 1 0 UR 3 18 33 UDRLR 17 11 132 RLDRDLDRUU 6 10 13 UULUDDLRDLUUDLDD 1 15 0 D 6 20 50 D...
output:
0 11 4 10 13 15 50 240 15 0 0 13 8 18 25 5 1 5 2 5 2 1 3 4 0 30 16 3 0 8 10 9 15 2 320 11 4 3 0 16 15 0 11 0 0 8 1 22 36 51 23 7 6 4 1 48 28 8 63 3 14 26 10 4 42 6 10 44 0 15 12 0 4 30 14 12 105 10 14 17 0 66 10 11 28 52 19 3 33 10 8 90 14 0 18 2 48 30 19 5 0 30 7 1 3 4 1 13 17 3 0 38 0 20 0 6 0 20 ...
result:
wrong answer 1st numbers differ - expected: '228', found: '0'