Submission #166031

# Submission time Handle Problem Language Result Execution time Memory
166031 2019-11-30T09:40:16 Z theStaticMind San (COCI17_san) C++14
120 / 120
61 ms 4088 KB
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
 //     freopen("q.gir","r",stdin);
 //     freopen("q.cik","w",stdout);
      int n,k,ans=0;
      cin>>n>>k;
      vector<int>arr(n+1,0),gold(n+1,0);
      map<int,map<int,int>>data,atad;
      data[0][0]=1;
      atad[INF][0]=1;
      for(int i=1;i<=n;i++)cin>>arr[i]>>gold[i];
      for(int i=1;i<=n/2;i++){
            map<int,int>temp;
            for(map<int,map<int,int>>::iterator it=data.begin();it!=data.end()&&it->first<=arr[i];it++){
                        for(map<int,int>::iterator itr=it->second.begin();itr!=it->second.end();itr++){
                              if(itr->first+gold[i]>=k){
                                    temp[k]+=itr->second;
                              }
                              else temp[itr->first+gold[i]]+=itr->second;
                        }
            }
            for(map<int,int>::iterator itr=temp.begin();itr!=temp.end();itr++)data[arr[i]][itr->first]+=itr->second;
      }
      for(int i=n;i>n/2;i--){
            map<int,int>temp;
            for(map<int,map<int,int>>::reverse_iterator it=atad.rbegin();it!=atad.rend()&&it->first>=arr[i];it++){
                        for(map<int,int>::iterator itr=it->second.begin();itr!=it->second.end();itr++){
                              if(itr->first+gold[i]>=k){
                                    temp[k]+=itr->second;
                              }
                              else temp[itr->first+gold[i]]+=itr->second;
                        }
            }
            for(map<int,int>::iterator itr=temp.begin();itr!=temp.end();itr++)atad[arr[i]][itr->first]+=itr->second;
      }
      map<int,map<int,int>>::iterator itrA=data.begin(),itrB=atad.begin();
      map<int,int>meet;
      for(;itrB!=atad.end();itrB++){
            while(itrA!=data.end()&&itrA->first<=itrB->first){
                  for(map<int,int>::iterator itr=itrA->second.begin();itr!=itrA->second.end();itr++){
                        meet[itr->first]+=itr->second;
                  }
                  itrA++;
            }
            map<int,int>::reverse_iterator curr=meet.rbegin();
            map<int,int> prefix;
            int cnt=0;
            for(;curr!=meet.rend();curr++){
                  prefix[curr->first]=curr->second+cnt;
                  cnt+=curr->second;
            }
            for(map<int,int>::iterator itr=itrB->second.begin();itr!=itrB->second.end();itr++){
                  map<int,int>::iterator get=prefix.lower_bound(k-itr->first);
                  if(get!=prefix.end())ans+=get->second*itr->second;
            }
      }
      cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 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
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1016 KB Output is correct
2 Correct 61 ms 4088 KB Output is correct