Submission #1010954

# Submission time Handle Problem Language Result Execution time Memory
1010954 2024-06-29T15:11:38 Z doducanh Sails (IOI07_sails) C++14
70 / 100
1000 ms 3496 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
#define h first
#define k second
const int maxn=1e5;
pair<int,int>a[maxn+7];
int dem[maxn+7];
int n;
main()
{
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i].h>>a[i].k;
    sort(a+1,a+n+1);
    for(int i=1;i<=n;i++){
        int k=a[i].k;
        int h=a[i].h;
        int pos=h-k;
        int l=pos,r=pos;
        if(pos){
            while(l>1&&dem[l-1]==dem[pos])l--;
            while(r<h&&dem[r+1]==dem[pos])r++;
        }

        for(int j=r+1;j<=h;j++)dem[j]++;
        for(int j=l;j<=l+(k-(h-r)-1);j++)dem[j]++;
//        for(int j=1;j<=5;j++)cout<<dem[j]<<" ";
//        cout<<"\n";
    }
    int ans=0;
    for(int i=1;i<=maxn;i++)ans+=1ll*dem[i]*(dem[i]-1)/2;
    cout<<ans;
    return 0;
}

Compilation message

sails.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 16 ms 1092 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 776 KB Output is correct
2 Correct 38 ms 1216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 1460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 393 ms 2136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 3084 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1069 ms 3412 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 3496 KB Time limit exceeded
2 Halted 0 ms 0 KB -