Submission #174631

#TimeUsernameProblemLanguageResultExecution timeMemory
174631CaroLindaDetecting Molecules (IOI16_molecules)C++14
9 / 100
2 ms380 KiB
#include "molecules.h" #include <bits/stdc++.h> #define debug printf #define lp(i,a,b) for(int i = a ; i < b ; i++ ) #define ff first #define ss second #define pb push_back #define mk make_pair #define ll long long #define sz size() #define pii pair<int,int> #define all(x) x.begin(),x.end() #define tiii tuple<int,int,int> #define mkt make_tuple const int MAXN = 2e5+10 ; using namespace std ; ll pref[MAXN] , suf[MAXN] ; vector<pii> id ; vector<int> find_subset(int l, int r, vector<int> w) { int tam = 1 ; bool ok = false ; vector<int> res ; lp(i,0,(int)(w.sz)) if( w[i] <= r) id.pb( mk(w[i],i) ) ; sort(all(id)) ; lp(i,0,(int)(id.sz)) pref[i] = ( i == 0 ? 0LL : pref[i-1] ) + id[i].ff ; for(int i = (int)(id).sz - 1 ; i >= 0 ; i-- ) suf[i] = suf[i+1] + id[i].ff ; if( suf[0] < 1LL * l ) return vector<int>(0) ; for(; tam <= (int)(id.sz) ; tam ++ ) if( suf[ (int)(id.sz)-tam ] > 1LL * r ) break ; tam -- ; if( suf[ (int)(id.sz)-tam ] >= 1LL * l ) { lp(i,(int)(id.sz)-tam, (int)(id.sz) ) res.pb( id[i].ss ) ; return res ; } if( pref[tam] > 1LL * r ) return res ; ll tot = suf[ (int)(id.sz)-tam ] ; int curId = (int)(id.sz)-tam ; for(int k = 0 ; k < tam ; k++ ) { tot -= id[curId].ff ; curId ++ ; tot += id[k].ff ; res.pb( id[k].ss ) ; if( tot >= 1LL*l && tot <= 1LL*r ) break ; } lp(i,curId, (int)(id.sz) ) res.pb( id[i].ss ) ; return res ; }

Compilation message (stderr)

molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:28:7: warning: unused variable 'ok' [-Wunused-variable]
  bool ok = false ;
       ^~
#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...