QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376787#4567. Admissible MapInfinityNSWA 0ms11936kbC++173.3kb2024-04-04 16:38:472024-04-04 16:38:48

Judging History

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

  • [2024-04-04 16:38:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11936kb
  • [2024-04-04 16:38:47]
  • 提交

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=20002;
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;
    }
}
bool pocetak[N],kraj[N];
int nxtNo[N];
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];
            }
        }
    }
    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++){
            pocetak[i]=kraj[i]=0;
            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);
            }
        }
        int no=-1;
        for(int i=n-1;i>=0;i--){
            if(need[i]==-1)no=i;
            nxtNo[i]=no;
        }
        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){
                pocetak[lst]=1;
                kraj[r+1]=1;
                lst=i+1;
                r=i+1;
            }
        }
        for(int i=0;i<=n-len;i++){
            if(pocetak[i]){
                int tr=i;
                bool ok=up[tr][tr+len-1]&&mid[tr][tr+len-1];
                tr+=len;
                while(ok&&tr<=nxtNo[i]){
                    if(down[tr-len][tr-1]&&kraj[tr]){
                        moze[i][tr-1]=1;
                    }
                    if(tr>n-len)break;
                    ok=ok&&mid[tr][tr+len-1];
                    tr+=len;
                }
            }
        }
    }
    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: 0
Wrong Answer
time: 0ms
memory: 11936kb

input:

RDUL

output:

1

result:

wrong answer 1st numbers differ - expected: '2', found: '1'