Submission #166030

#TimeUsernameProblemLanguageResultExecution timeMemory
166030theStaticMindSan (COCI17_san)C++14
0 / 120
18 ms1144 KiB
#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; void print(map<int,int>& data){ for(map<int,int>::iterator itr=data.begin();itr!=data.end();itr++)cout<<itr->first<<"->"<<itr->second<<"\n";cout<<"\n"; } void print(map<int,map<int,int>>&data){ for(map<int,map<int,int>>::iterator itr=data.begin();itr!=data.end();itr++){ cout<<"for "<<itr->first<<":\n"; print(itr->second); } } 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; } print(atad); 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; }

Compilation message (stderr)

san.cpp: In function 'void print(std::map<long long int, long long int>&)':
san.cpp:12:7: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
       for(map<int,int>::iterator itr=data.begin();itr!=data.end();itr++)cout<<itr->first<<"->"<<itr->second<<"\n";cout<<"\n";
       ^~~
san.cpp:12:115: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
       for(map<int,int>::iterator itr=data.begin();itr!=data.end();itr++)cout<<itr->first<<"->"<<itr->second<<"\n";cout<<"\n";
                                                                                                                   ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...