Submission #170564

# Submission time Handle Problem Language Result Execution time Memory
170564 2019-12-25T15:54:05 Z mdn2002 Unija (COCI17_unija) C++14
80 / 100
1000 ms 50220 KB
#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
multiset<int>ms;
int n,k;
int v[1000006],a[10000007];
vector<int>b;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("lemonade.in","r",stdin);
    //freopen("lemonade.out","w",stdout);
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        int x,y;
        scanf("%d",&x);
        scanf("%d",&y);
        x/=2;
        y/=2;
        if(a[y+1]==0)
        {
            a[y+1]=++k;
            b.push_back(y+1);
        }
        if(v[a[y+1]]==0)
        {
            v[a[y+1]]=x;
            continue;
        }
        if(v[a[y+1]]<x)v[a[y+1]]=x;
    }
    for(int i=0;i<b.size();i++)ms.insert(v[a[b[i]]]);
    sort(b.begin(),b.end());
    long long ans=0;
    for(int i=0;i<b.size();i++)
    {
        int z=b[i],z1;
        if(i>0)z1=b[i-1];
        else z1=1;
        ans+=*--ms.end()*(z-z1);
        if(v[a[z]]!=0)
        {
            int x=v[a[z]];
            ms.erase(ms.lower_bound(x));
        }
        if(ms.size()==0)break;
    }
    cout<<ans*4;
}

Compilation message

unija.cpp: In function 'int main()':
unija.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<b.size();i++)ms.insert(v[a[b[i]]]);
                 ~^~~~~~~~~
unija.cpp:38:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<b.size();i++)
                 ~^~~~~~~~~
unija.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
unija.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
unija.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&y);
         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 50220 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1784 KB Output is correct
2 Correct 23 ms 1784 KB Output is correct
3 Correct 22 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 5168 KB Output is correct
2 Correct 75 ms 5188 KB Output is correct
3 Correct 75 ms 5108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 344 ms 14740 KB Output is correct
2 Correct 317 ms 14700 KB Output is correct
3 Correct 319 ms 14828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 46544 KB Time limit exceeded
2 Halted 0 ms 0 KB -