QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720420#9141. Array SpreadhuaxiamengjinWA 2ms9748kbC++141.9kb2024-11-07 12:36:542024-11-07 12:36:55

Judging History

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

  • [2024-11-07 12:36:55]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:9748kb
  • [2024-11-07 12:36:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=4005,mod=998244353;
int n,m,l[M],r[M],mn[M][M],mx[M][M];
struct info{int p,q;
    bool operator <(const info &a) const
        {return 1ll*p*a.q<1ll*a.p*q;}
}ans;
int tot,a[M];
int qpow(int x,int n){
    int s=1; while (n){
        if (n&1) s=1ll*s*x%mod;
        x=1ll*x*x%mod; n>>=1;
    } return s;
}
int test,TT;
vector<int>g[100100];
void solve(){
    test++;
    cin>>n>>m;ans={1,1};tot=0;
    for (int i=1;i<=m;i++) cin>>l[i]>>r[i],a[++tot]=l[i],a[++tot]=r[i],a[++tot]=r[i]-1;
    sort(a+1,a+tot+1);
    tot=unique(a+1,a+tot+1)-a-1;
    for (int i=1;i<=tot;i++)
    g[i].clear();
    for (int i=1;i<=m;i++)
    l[i]=lower_bound(a+1,a+tot+1,l[i])-a,
    r[i]=lower_bound(a+1,a+tot+1,r[i])-a,
    g[r[i]].push_back(l[i]);
    n=tot;
    // cout<<tot<<"******\n";
    for (int i=1;i<=n+1;i++)
        for (int j=1;j<=n+1;j++)
            mn[i][j]=0x3f3f3f3f,mx[i][j]=0;
    for (int i=1;i<=m;i++) 
        mx[l[i]][r[i]]=mn[l[i]][r[i]]=1;
    for (int len=n;len;len--){
        for (int l=1;l+len-1<=n;l++){
            int r=l+len-1;
            mn[l][r]=min(mn[l][r+1],mn[l-1][r]);
        }
    }
    for (int l=n;l;l--)
        for (int r=l;r<=n;r++){
            mx[l][r]=mx[l][r-1];
            for (auto k:g[r])if(k>=l)
            mx[l][r]=max(mx[l][r],mx[l][k-1]+1);
        }
    for (int l=n;l;l--)
        for (int r=l;r<=n;r++)
            for (int k=l;k<r;k++){
                if(a[k]+1==a[k+1])
                mn[l][r]=min(mn[l][r],mn[l][k]+mn[k+1][r]);
            }
    for (int i=1;i<=n;i++)
        for (int j=i;j<=n;j++)
            if (mx[i][j])
            ans=max(ans,{mx[i][j],mn[i][j]});
    cout<<1ll*ans.p*qpow(ans.q,mod-2)%mod<<'\n';
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T;cin>>T;TT=T;
    while (T--) solve();return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 9748kb

input:

3
3 3
1 3
2 3
1 2
12 6
2 3
5 7
1 9
4 8
1 2
7 11
4 5
3 4
2 3
1 2
4 4
1 1

output:

0
0
0

result:

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