Submission #113811

#TimeUsernameProblemLanguageResultExecution timeMemory
113811Mamnoon_SiamMinerals (JOI19_minerals)C++17
40 / 100
89 ms5112 KiB
#include "minerals.h" #include <bits/stdc++.h> using namespace std; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } struct RNG { int operator () (int n) { return rnd(n); } }; void scattered(vector<int> u, vector<int> v) { assert(u.size() == v.size()); if(u.empty()) return; if(u.size() == 1) { Answer(u.back(), v.back()); return; } int mid = ((int)u.size() - 2) >> 1; int last; for(int i = 0; i <= mid; i++) { last = Query(v[i]); } vector<int> lu, lv(v.begin(), v.begin() + mid + 1), ru, rv(v.begin() + mid + 1, v.end()); for(int i = 0; i < u.size(); i++) { int rep = Query(u[i]); if(rep == last) { lu.emplace_back(u[i]); } else { ru.emplace_back(u[i]); } last = rep; } for(int i = 0; i <= mid; i++) { Query(v[i]); } scattered(lu, lv); scattered(ru, rv); } void together(vector<int> v) { if(v.empty()) return; if(v.size() == 2) { Answer(v[0], v[1]); return; } random_shuffle(v.begin(), v.end(), RNG()); int mid = ((int)v.size()) / 2 - 1; vector<int> l, r, dl, dr; int last = 0; for(int i = 0; i <= mid; i++) { int rep = Query(v[i]); if(rep == last) { l.emplace_back(v[i]); } last = rep; } for(int i = 0; i <= mid; i++) { int rep = Query(v[i]); if(rep == last) { l.emplace_back(v[i]); } last = rep; } last = 0; for(int i = mid + 1; i < v.size(); i++) { int rep = Query(v[i]); if(rep == last) { r.emplace_back(v[i]); } last = rep; } for(int i = mid + 1; i < v.size(); i++) { int rep = Query(v[i]); if(rep == last) { r.emplace_back(v[i]); } last = rep; } set<int> sl(l.begin(), l.end()), sr(r.begin(), r.end()); for(int i = 0; i <= mid; i++) { if(sl.find(v[i]) == sl.end()) { dl.emplace_back(v[i]); } } for(int i = mid + 1; i < v.size(); i++) { if(sr.find(v[i]) == sr.end()) { dr.emplace_back(v[i]); } } together(l); together(r); scattered(dl, dr); } void Solve(int N) { vector<int> v(2 * N); iota(v.begin(), v.end(), 1); together(v); }

Compilation message (stderr)

minerals.cpp: In function 'void scattered(std::vector<int>, std::vector<int>)':
minerals.cpp:26:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < u.size(); i++) {
                 ~~^~~~~~~~~~
minerals.cpp: In function 'void together(std::vector<int>)':
minerals.cpp:69:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = mid + 1; i < v.size(); i++) {
                       ~~^~~~~~~~~~
minerals.cpp:76:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = mid + 1; i < v.size(); i++) {
                       ~~^~~~~~~~~~
minerals.cpp:89:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = mid + 1; i < v.size(); i++) {
                       ~~^~~~~~~~~~
minerals.cpp: In function 'void scattered(std::vector<int>, std::vector<int>)':
minerals.cpp:28:3: warning: 'last' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(rep == last) {
   ^~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...