QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376286#4567. Admissible MapInfinityNSTL 2074ms477288kbC++173.4kb2024-04-04 02:05:512024-04-04 02:05:52

Judging History

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

  • [2024-04-04 02:05:52]
  • 评测
  • 测评结果:TL
  • 用时:2074ms
  • 内存:477288kb
  • [2024-04-04 02:05:51]
  • 提交

answer

#include<bits/stdc++.h>
#define sz(x) (int)(x).size()
#define f first
#define s second
#define pb push_back
#define ll long long
#define all(x) (x).begin(),(x).end()
using namespace std;
// 19:33
const int N=20001;
bool moze[N][N];
int visited[N];
bool inc[N];
int nxt[N];
int need[N];
bool mid[N][N],up[N][N],down[N][N];
int dfs(int tr){
    if(nxt[tr]==-1){
        inc[tr]=0;
        visited[tr]=1;
        return -1;
    }
    if(visited[nxt[tr]]==1){
        inc[tr]=0;
        visited[tr]=1;
        return -1;
    }
    if(visited[nxt[tr]]==2){
        inc[tr]=1;
        visited[tr]=1;
        return nxt[tr];
    }
    visited[tr]=2;
    int r=dfs(nxt[tr]);
    visited[tr]=1;
    if(r==-1){
        inc[tr]=0;
        return -1;
    }
    else{
        inc[tr]=1;
        if(tr==r)return -1;
        return r;
    }
}
int main(){
    string s;
    cin >> s;
    int n=sz(s);
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            mid[i][j]=s[i]!='L'&&s[j]!='R';
            up[i][j]=s[j]!='U';
            down[i][j]=s[j]!='D';
            if(i!=j){
                up[i][j]=up[i][j]&&up[i][j-1];
                down[i][j]=down[i][j]&&down[i][j-1];
            }
        }
    }
    vector<pair<int,int>> its;
    for(int len=1;len<=n;len++){
        for(int i=0;i<n;i++){
            inc[i]=0;
            visited[i]=0;
            if(s[i]=='L'){
                nxt[i]=i-1;
            }
            if(s[i]=='R'){
                nxt[i]=i==n-1?-1:i+1;
            }
            if(s[i]=='U'){
                nxt[i]=i<len?-1:i-len;
            }
            if(s[i]=='D'){
                nxt[i]=i>=n-len?-1:i+len;
            }
            need[i]=0;
        }
        for(int i=0;i<n;i++){
            if(!visited[i]){
                dfs(i);
            }
            if(nxt[i]==-1||!inc[i]){
                need[i]=-1;
            }
            if(need[i]==-1)continue;
            if(nxt[i]>i){
                need[i]=max(need[i],nxt[i]);
            }
            else{
                need[nxt[i]]=max(need[nxt[i]],i);
            }
        }
        its.clear();
        int r=0;
        int lst=0;
        for(int i=0;i<n;i++){
            if(need[i]==-1){
                lst=i+1;
                r=i+1;
                continue;
            }
            r=max(r,need[i]);
            if(r==i){
                its.pb({lst,r});
                lst=i+1;
                r=i+1;
            }
        }
        for(int i=0;i<sz(its);i++){
            int tr=its[i].f;
            bool ok=up[tr][tr+len-1]&&mid[tr][tr+len-1];
            tr+=len;
            for(int j=i;ok&&j<sz(its);j++){
                int en=its[j].s;
                if((en-its[i].f+1)%len==0){
                    while(tr+len-1<=en){
                        if(!mid[tr][tr+len-1]){
                            ok=0;
                            break;
                        }
                        tr+=len;
                    }
                    if(!ok)break;
                    if(en+1==tr&&down[tr-len][tr-1]){
                        moze[its[i].f][its[j].s]=1;
                    }
                }
                if(j==sz(its)-1)continue;
                if(its[j+1].f!=its[j].s+1)break;
            }
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)for(int j=i;j<n;j++)ans+=moze[i][j];
    printf("%i\n",ans);
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 11944kb

input:

RDUL

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 9896kb

input:

RDRU

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 11928kb

input:

RLRLRL

output:

6

result:

ok 1 number(s): "6"

Test #4:

score: 0
Accepted
time: 2ms
memory: 9940kb

input:

D

output:

0

result:

ok 1 number(s): "0"

Test #5:

score: 0
Accepted
time: 2ms
memory: 11860kb

input:

DL

output:

0

result:

ok 1 number(s): "0"

Test #6:

score: 0
Accepted
time: 2ms
memory: 9856kb

input:

RL

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 0ms
memory: 9928kb

input:

DU

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 2ms
memory: 9956kb

input:

RDULU

output:

2

result:

ok 1 number(s): "2"

Test #9:

score: 0
Accepted
time: 0ms
memory: 11900kb

input:

RDDUULRDDD

output:

2

result:

ok 1 number(s): "2"

Test #10:

score: 0
Accepted
time: 2ms
memory: 12028kb

input:

RLRLRLRLRL

output:

15

result:

ok 1 number(s): "15"

Test #11:

score: 0
Accepted
time: 2ms
memory: 9892kb

input:

DUDUDUDUDU

output:

15

result:

ok 1 number(s): "15"

Test #12:

score: 0
Accepted
time: 0ms
memory: 9852kb

input:

RDRDULULRR

output:

3

result:

ok 1 number(s): "3"

Test #13:

score: 0
Accepted
time: 0ms
memory: 12312kb

input:

UUURDRDRDLRULLRLULUDRURDRULLRU

output:

2

result:

ok 1 number(s): "2"

Test #14:

score: 0
Accepted
time: 2ms
memory: 12276kb

input:

RLRLRLRLRLRLRLRLRLRLRLRLRLRLRL

output:

120

result:

ok 1 number(s): "120"

Test #15:

score: 0
Accepted
time: 0ms
memory: 12020kb

input:

DUDUDUDUDUDUDUDUDUDUDUDUDUDUDU

output:

120

result:

ok 1 number(s): "120"

Test #16:

score: 0
Accepted
time: 2ms
memory: 12068kb

input:

RDRDRDRDRDRDRDULULULULULULULDL

output:

8

result:

ok 1 number(s): "8"

Test #17:

score: 0
Accepted
time: 0ms
memory: 18468kb

input:

DLURRURRLDDUUDRDURDDLRLULLULDUULDDRDUURLLDDLRRLUDURLLRRRLLRLUDULDULUUDLLDLRLULDDURDDDLLUURRDRRDDRULU

output:

18

result:

ok 1 number(s): "18"

Test #18:

score: 0
Accepted
time: 0ms
memory: 16464kb

input:

RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL

output:

1275

result:

ok 1 number(s): "1275"

Test #19:

score: 0
Accepted
time: 0ms
memory: 18480kb

input:

DUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDU

output:

1275

result:

ok 1 number(s): "1275"

Test #20:

score: 0
Accepted
time: 3ms
memory: 16208kb

input:

RDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDULULULULULULULULULULULULULULULULULULULULULULULULUL

output:

26

result:

ok 1 number(s): "26"

Test #21:

score: 0
Accepted
time: 0ms
memory: 34948kb

input:

LRULLRUURRDUULDRULLLRLUDLDRUUURRDDRDLLDDRLUDLRLRRLRRUDUUULDDLUDUDRURUDLLRLDRLLDULRRURLDLDDDLUUUDRRUDRDURRRDLLDRDRRDULULRLLULULDLDLUURRRLRRUUUUDUUUULLURLUUDLURDUDDUDDURDDURRRLURDLUDDDDLRLDULRRRULLDDDDLLLDDLUDURDURLDDUDDRDLLULRRUDRRDRRRLUUULRLDDDDDDURRDULUDDDLDLLUDDUUDDDLLRDDRLRRLRDLDUDUDRULURRRULRLRD

output:

43

result:

ok 1 number(s): "43"

Test #22:

score: 0
Accepted
time: 3ms
memory: 35180kb

input:

RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL

output:

11325

result:

ok 1 number(s): "11325"

Test #23:

score: 0
Accepted
time: 0ms
memory: 34812kb

input:

DUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDU

output:

11325

result:

ok 1 number(s): "11325"

Test #24:

score: 0
Accepted
time: 0ms
memory: 32700kb

input:

RDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULULUL

output:

76

result:

ok 1 number(s): "76"

Test #25:

score: 0
Accepted
time: 13ms
memory: 90216kb

input:

LRRDDUUDLRLDLLRRDRLRDRLUDURURLLDURDLUDDRDLRLUULRLLDLRRRLDRRULRRULURRUDURRDLULLLDDRURLLURURLRRRRLURLURUUDRURDLLRUDDLULDLLRULRURDLRDUULURDULLLRLRDLRRUDUUUDUDLLRULRRRDRLLRRURRRRRLRDULDURRDLDULLURLLLURLRLDDRURULLDULULDRLDRLUUDDULLDRRDRURURDUUDDRDULRRUUDULULDDLRDURUUUURULLURRUDRURLUDLLUURRULRURDDRDRLUDUU...

output:

168

result:

ok 1 number(s): "168"

Test #26:

score: 0
Accepted
time: 84ms
memory: 88144kb

input:

RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL...

output:

125250

result:

ok 1 number(s): "125250"

Test #27:

score: 0
Accepted
time: 7ms
memory: 90256kb

input:

DUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDU...

output:

125250

result:

ok 1 number(s): "125250"

Test #28:

score: 0
Accepted
time: 7ms
memory: 79984kb

input:

RDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRD...

output:

251

result:

ok 1 number(s): "251"

Test #29:

score: 0
Accepted
time: 130ms
memory: 246428kb

input:

RDLRLLLLDDLDUUURUDUDUDUURURLRURLURLRLUULLRUDUURLDDRRDRUULDUURUDUUDLRLDUUUDRLLDRRDLLULDULRDURLLRLUDDRRLUDURRUUDULDLDLLDDUDURDLULRLLDRDRURUDLRDUDULLDUDDLRRRUDLLLRDLLRDDLDRDLRUUUUDRRDLDUUURDUUDUDDURUDRLDRRUURDUDDRRDDDULDRURDUURDUUDDRRDLRURRDUUDLDLRDULLLDDRLDRRLURLUUDRDDUDLDULDLRDDUUURRURURDUUDULULDDDRL...

output:

491

result:

ok 1 number(s): "491"

Test #30:

score: 0
Accepted
time: 2074ms
memory: 245924kb

input:

RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL...

output:

1125750

result:

ok 1 number(s): "1125750"

Test #31:

score: 0
Accepted
time: 56ms
memory: 246156kb

input:

DUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDUDU...

output:

1125750

result:

ok 1 number(s): "1125750"

Test #32:

score: 0
Accepted
time: 47ms
memory: 216996kb

input:

RDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRDRD...

output:

751

result:

ok 1 number(s): "751"

Test #33:

score: 0
Accepted
time: 546ms
memory: 477288kb

input:

LULDRUDLRRRRDRLRUUURDUUDLLUURDLRDRDDDURLUUDLRLRLUDRURDRRUDLRRLRURDDURURDRLULUULRDDLDLDLRLLLRLRRRLUDDLUDLDLURLUUDDDLLDUDLDRUULRLRUUDRDUUDLDLLDDLRUULRLUUDRRDLLLDLDUULLDDDLDRRRDDDDUUUULLLULRLLLLLDDDLLRDLDULDDDLRULRRDUULRLULRRDULDUULDURLRLDDLLLLRLLULDLRLDRRDLRULDRDDLDLUUUULUUDUDRDULUDRUDLUULRLRULULLUDRU...

output:

936

result:

ok 1 number(s): "936"

Test #34:

score: -100
Time Limit Exceeded

input:

RLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRLRL...

output:


result: