답안 #109206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
109206 2019-05-05T13:51:16 Z nikolapesic2802 Sails (IOI07_sails) C++14
0 / 100
1000 ms 8340 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int n;
const int N=1e5+5;
vector<vector<int> > jar(N);
ll sol=LLONG_MAX;
bool test(int m)
{
    multiset<int> veci;
    multiset<int,greater<int> > manji;
    ll trsol=0;
    int offset=0;
    for(int j=N-1;j>=0;j--)
    {
        for(auto p:jar[j])
            manji.insert(p);
        while(veci.size()&&*veci.begin()-offset<=0)
            veci.erase(veci.begin());
        while(veci.size()<m&&manji.size())
        {
            veci.insert(*manji.begin()+offset);
            manji.erase(manji.begin());
        }
        while(manji.size()&&veci.size()&&*manji.begin()>*veci.begin()-offset)
        {
            int a=*manji.begin();
            int b=*veci.begin()-offset;
            manji.erase(manji.begin());
            veci.erase(veci.begin());
            manji.insert(b);
            veci.insert(a+offset);
        }
        trsol+=(ll)veci.size()*((ll)veci.size()-1)/2;
        offset++;
    }
    while(veci.size()&&*veci.begin()-offset<=0)
        veci.erase(veci.begin());
    bool ret=veci.size()==0&&manji.size()==0;
    if(ret)
        sol=min(sol,trsol);
    return ret;
}
int main()
{
	scanf("%i",&n);
	jar.resize(n);
	for(int i=0;i<n;i++)
    {
        int a,b;
        scanf("%i %i",&a,&b);
        jar[a].pb(b);
    }
    int l=0,r=N;
    while(l<r)
    {
        int m=(l+r)>>1;
        if(test(m))
            r=m;
        else
            l=m+1;
    }
    test(l);
    printf("%lld\n",sol);
    return 0;
}

Compilation message

sails.cpp: In function 'bool test(int)':
sails.cpp:42:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(veci.size()<m&&manji.size())
               ~~~~~~~~~~~^~
sails.cpp: In function 'int main()':
sails.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i",&n);
  ~~~~~^~~~~~~~~
sails.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%i %i",&a,&b);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 2688 KB Output is correct
2 Incorrect 8 ms 2688 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 2688 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1063 ms 2788 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 3488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 5376 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1077 ms 5712 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1061 ms 7672 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1065 ms 8340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1067 ms 8180 KB Time limit exceeded
2 Halted 0 ms 0 KB -