Submission #50742

#TimeUsernameProblemLanguageResultExecution timeMemory
50742Mamnoon_SiamDetecting Molecules (IOI16_molecules)C++17
9 / 100
3 ms612 KiB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include "molecules.h" #include <bits/stdc++.h> using namespace std; #define debug(s) cout<< #s <<" = "<< s <<endl #define all(v) (v).begin(), (v).end() #define KeepUnique(v) (v).erase( unique(all(v)), v.end() ) #define MEMSET(a,val) memset(a, val, sizeof a) #define PB push_back #define endl '\n' typedef long long ll; inline int myrand(int l, int r) { int ret = rand(); ret <<= 15; ret ^= rand(); if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l; return ret; } template <typename F, typename S> ostream& operator << (ostream& os, const pair< F, S>& p) { return os<<"(" <<p.first<<", "<<p.second<<")"; } typedef pair<int, int> ii; template<typename T> using min_pq = priority_queue<T, vector<T>, greater<T> >; //int dx[] = {-1, +0, +1, +0}; //int dy[] = {+0, +1, +0, -1}; vector<ll> a, idx; ll l, r; vector<int> get_prefix(int k) { vector<int> ret; for(int i = 0; i < k; i++) { ret.push_back(idx[i]); } return ret; } vector<int> get_suffix(int k) { vector<int> ret; for(int i = 0, j = a.size() - 1; i < k; i++, j--) { ret.push_back(idx[j]); } return ret; } vector<int> subarray(int x, int y) { vector<int> ret; for(int i = x; i <= y; i++) { ret.push_back(idx[i]); } return ret; } vector<int> get_whole(int k) { ll s = 0; for(int i = 0; i < k; i++) s += a[i]; int lp = 0, rp = k - 1; while(true) { s -= a[++lp]; s += a[++rp]; if(l <= s and s <= r) { return subarray(lp, rp); } } } vector<int> find_subset(int L, int R, vector<int> w) { l = L, r = R; for(int i = 0; i < w.size(); i++) { idx.push_back(i); a.push_back(w[i]); } sort(all(idx), [](int x, int y){return a[x] < a[y];}); sort(all(a)); ll pre = 0, suf = 0; for(int i = 1; i <= a.size(); i++) { pre += a[i - 1], suf += a[a.size() - i]; if(l <= pre and pre <= r) return get_prefix(i); if(l <= suf and pre <= r) return get_suffix(i); if(pre < l and r < suf) return get_whole(i); } return vector<int>(); }

Compilation message (stderr)

molecules.cpp: In function 'int myrand(int, int)':
molecules.cpp:18:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
  ^~
molecules.cpp:18:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
                          ^~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:70:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < w.size(); i++) {
                    ~~^~~~~~~~~~
molecules.cpp:77:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i <= a.size(); i++) {
                    ~~^~~~~~~~~~~
#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...