Submission #898418

# Submission time Handle Problem Language Result Execution time Memory
898418 2024-01-04T16:07:40 Z abcvuitunggio Fish (IOI08_fish) C++17
56 / 100
3000 ms 17748 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,k,m,res,ch[500001],pos[500001],ban[500001],cnt[500001];
pair <int, int> f[500001];
int32_t main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n >> k >> m;
    for (int i=1;i<=n;i++){
        cin >> f[i].first >> f[i].second;
        if (!pos[f[i].second])
            pos[f[i].second]=f[i].first;
        pos[f[i].second]=min(pos[f[i].second],f[i].first);
    }
    sort(f+1,f+n+1);
    for (int i=n;i;i--){
        if (ch[f[i].second])
            continue;
        for (int j=n;j>i;j--)
            if (f[j].first>=pos[f[i].second]*2)
                ban[f[j].second]=1;
        for (int j=1;j<i;j++)
            if (f[j].first*2<=f[i].first)
                cnt[f[j].second]++;
        int x=1;
        ban[f[i].second]=1;
        for (int i=1;i<=k;i++)
            if (!ban[i])
                x=x*(cnt[i]+1)%m;
        res=(res+x*(cnt[f[i].second]+1))%m;
        ch[f[i].second]=i;
        int l=0;
        for (int j=1;j<=n;j++)
            if (f[j].first*2>f[i].first&&f[j].second==f[i].second){
                l=f[j].first;
                break;
            }
        int y=1;
        for (int j=i+1;j<=n;j++)
            if (f[j].first>=pos[f[i].second]*2&&l*2>f[j].first&&ch[f[j].second]==j)
                y=y*(cnt[f[j].second]+1)%m;
        res=(res+x*(y+m-1))%m;
        for (int j=1;j<=k;j++)
            ban[j]=cnt[j]=0;
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 108 ms 10896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 8848 KB Output is correct
2 Correct 127 ms 8784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 4440 KB Output is correct
2 Correct 13 ms 4444 KB Output is correct
3 Correct 23 ms 4668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 613 ms 10924 KB Output is correct
2 Correct 1930 ms 17616 KB Output is correct
3 Correct 1610 ms 17636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3033 ms 10920 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2242 ms 10956 KB Output is correct
2 Execution timed out 3066 ms 17748 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3047 ms 10836 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3039 ms 11172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3051 ms 11348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3053 ms 16004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3028 ms 15188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3037 ms 17148 KB Time limit exceeded
2 Halted 0 ms 0 KB -