답안 #166030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166030 2019-11-30T09:39:29 Z theStaticMind San (COCI17_san) C++14
0 / 120
18 ms 1144 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;
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

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";
                                                                                                                   ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -