Submission #521479

#TimeUsernameProblemLanguageResultExecution timeMemory
521479errorgornAkcija (COCI21_akcija)C++17
110 / 110
2962 ms63612 KiB
// Super Idol的笑容 // 都没你的甜 // 八月正午的阳光 // 都没你耀眼 // 热爱105°C的你 // 滴滴清纯的蒸馏水 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << ": " << x << endl #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define lb lower_bound #define ub upper_bound #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); int n,k; ii arr[2005]; ll w[2005]; ll d[2005]; ii memo[2005][2005]; ii dp(int i,int j){ if (i==n) return {0,0}; if (memo[i][j]!=ii(-1,-1)) return memo[i][j]; ii res=dp(i+1,j); if (j<d[i]){ ii temp=dp(i+1,j+1); temp.fi++,temp.se+=w[i]; res=max(res,temp); } return memo[i][j]=res; } vector<ii> ans; void search(int i,int j,ll num,ll tot){ if (i==n){ if (ii(num,tot)<ii(0,0)) ans.pub({num,tot}); return; } if (dp(i,j)<=ii(num,tot)) return; search(i+1,j,num,tot); if (sz(ans)==k) return; if (j<d[i]) search(i+1,j+1,num-1,tot-w[i]); } bool smaller(ll num,ll tot){ ans.clear(); search(0,0,num,tot); return sz(ans)<k; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin>>n>>k; const int pad=1e9; rep(x,0,n) cin>>arr[x].fi>>arr[x].se; sort(arr,arr+n,[](ii i,ii j){ return i.se<j.se; }); rep(x,0,n) tie(w[x],d[x])=arr[x]; rep(x,0,n) w[x]=pad-w[x]; memset(memo,-1,sizeof(memo)); ll hi=2e16,lo=-1,mi; ll mxw=2e9*2000; while (hi-lo>1){ mi=hi+lo>>1; ll num=mi/mxw,tot=mi%mxw; if (smaller(num,tot)) hi=mi; else lo=mi; } ll num=hi/mxw,tot=hi%mxw; //cout<<"debug: "<<num<<" "<<tot<<endl; ans.clear(); search(0,0,num,tot); for (auto &it:ans) it={num-it.fi,tot-it.se}; sort(all(ans)); reverse(all(ans)); while (sz(ans)<k) ans.pub({num,tot}); for (auto &it:ans){ cout<<it.fi<<" "<<it.fi*pad-it.se<<endl; } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:103:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  103 |   mi=hi+lo>>1;
      |      ~~^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...