Submission #286498

#TimeUsernameProblemLanguageResultExecution timeMemory
286498PuddlestompsScales (IOI15_scales)C++17
0 / 100
1 ms256 KiB
#include "bits/stdc++.h" #define TESTING 0 #if TESTING #include "graderlib.c" #else #include "scales.h" #endif using namespace std; /* bool lessThan(int a, int b, int val, bool lower = false) { if(lower) //val is lower than a and b { int k = getMedian(a, b, val); if(k == a) return true; else return false; } else { int k = getLightest(a, b, val); if(k == a) return true; else return false; } } void swap(int* a, int* b) { if(a == b) return; *a = (*a) ^ (*b); *b = (*a) ^ (*b); *a = (*a) ^ (*b); } void sort(int* begin, int* end, int mid = -1, bool less = false) { if(end - begin == 1) return; if(end - begin == 2) { if(lessThan(*begin, *(end - 1), mid, less)) swap(begin, end - 1); return; } int first = *begin, second = *(begin + 1), third = *(begin + 2); int mid = getMedian(first, second, third); int* m = nullptr; if(mid == first) m = begin; else if(mid == second) m = begin + 1; else m = begin + 2; int* back = end - 1; swap(m, back); --back; int* front = begin; while(front != back) { if(*front) } }*/ void init(int T) { /* ... */ } void solve1() { set<int> unsorted = {1, 2, 3, 4, 5, 6}; int W[] = {1, 2, 3, 4, 5, 6}; int l1 = getLightest(1, 2, 3); int l2 = getLightest(6, 4, 5); int other = 1; if(other == l1 || other == l2) other++; if(other == l1 || other == l2) other++; int l = getLightest(other, l1, l2); unsorted.erase(l); //int lind = l - 1; W[0] = l; //First coin is now sorted if(TESTING) cerr << "W[0] = " << l << "\n"; auto it = unsorted.begin(); auto it2 = it++; auto it3 = it++; l1 = getLightest(*it, *it2, *it3); it++; auto it5 = it++; l = getLightest(l1, *it, *it5); unsorted.erase(l); W[1] = l; //second coin sorted if(TESTING) cerr << "W[1] = " << l << "\n"; it = unsorted.begin(); it2 = it++; it3 = it++; l1 = getLightest(*it, *it2, *it3); auto othern = unsorted.begin(); if(*othern == l1) othern++; it++; l2 = getLightest(l1, *othern, *it); unsorted.erase(l2); W[2] = l2; //third coin sorted; if(TESTING) cerr << "W[2] = " << l2 << "\n"; it = unsorted.begin(); it2 = it++; it3 = it++; l1 = getLightest(*it, *it2, *it3); W[3] = l1; if(TESTING) cerr << "W[3] = " << l1 << "\n"; l2 = getMedian(*it, *it2, *it3); W[4] = l2; if(TESTING) cerr << "W[4] = " << l2 << "\n"; unsorted.erase(l1); unsorted.erase(l2); l1 = *unsorted.begin(); W[5] = l1; if(TESTING) cerr << "W[5] = " << l1 << "\n"; answer(W); } void solve2() { int W[6] = {1, 2, 3, 4, 5, 6}; vector<int> A = {0, 0, 0}, B = {0, 0, 0}; A[0] = getLightest(1, 2, 3); A[1] = getMedian(1, 2, 3); A[2] = 6 - A[1] - A[0]; B[0] = getLightest(4, 5, 6); B[1] = getMedian(4, 5, 6); B[2] = 15 - B[1] - B[0]; int ind = 1; int a = getNextLightest(4, 5, 6, A[0]); if(a == B[0]) { int b = getLightest(A[0], B[0], B[1]); if(b == B[0]) { W[0] = B[0]; W[1] = B[1]; W[2] = B[2]; W[3] = A[0]; W[4] = A[1]; W[5] = A[2]; answer(W); return; } W[0] = A[0]; B.insert(B.begin(), A[0]); A.erase(A.begin()); ind = 0; } else { for(ind; ind < 3; ind++) if(B[ind] == a) { break; } B.insert(B.begin() + ind, A[0]); A.erase(A.begin()); } a = getNextLightest(B[1], B[2], B[3], A[0]); if(a == B[1]) { if(ind != 0) { W[0] = B[0]; W[1] = B[1]; W[2] = B[2]; W[3] = B[3]; W[4] = A[0]; W[5] = A[1]; answer(W); return; } int b = getLightest(A[0], B[1], B[2]); if(b == B[1]) { W[0] = B[0]; W[1] = B[1]; W[2] = B[2]; W[3] = B[3]; W[4] = A[0]; W[5] = A[1]; answer(W); return; } W[1] = A[0]; B.insert(B.begin() + 1, A[0]); A.erase(A.begin()); ind = 1; } else { ind = 2; for(ind; ind < 4; ind++) if(B[ind] == a) { break; } B.insert(B.begin() + ind, A[0]); A.erase(A.begin()); } a = getNextLightest(B[2], B[3], B[4], A[0]); if(a == B[2]) { if(ind >= 2) { W[0] = B[0]; W[1] = B[1]; W[2] = B[2]; W[3] = B[3]; W[4] = B[4]; W[5] = B[5]; answer(W); return; } int b = getLightest(A[0], B[2], B[3]); if(b == B[2]) { W[0] = B[0]; W[1] = B[1]; W[2] = B[2]; W[3] = B[3]; W[4] = B[4]; W[5] = B[5]; answer(W); return; } W[2] = A[0]; B.insert(B.begin() + 2, A[0]); A.erase(A.begin()); ind = 1; } else { ind = 3; for(ind; ind < 5; ind++) if(B[ind] == a) { break; } B.insert(B.begin() + ind, A[0]); A.erase(A.begin()); } W[0] = B[0]; W[1] = B[1]; W[2] = B[2]; W[3] = B[3]; W[4] = B[4]; W[5] = B[5]; if(TESTING) { cerr << "W: "; for (int i = 0; i < 6; i++) cerr << W[i] << " "; cerr << "\n"; } answer(W); return; } void orderCoins() { solve2(); } #if TESTING int main() { int T, i; T = _getNumberOfTests(); init(T); for (i = 1; i <= T; i++) { _initNewTest(); orderCoins(); } return 0; } #endif

Compilation message (stderr)

scales.cpp: In function 'void init(int)':
scales.cpp:67:15: warning: unused parameter 'T' [-Wunused-parameter]
   67 | void init(int T)
      |           ~~~~^
scales.cpp: In function 'void solve2()':
scales.cpp:172:13: warning: statement has no effect [-Wunused-value]
  172 |         for(ind; ind < 3; ind++) if(B[ind] == a)
      |             ^~~
scales.cpp:219:13: warning: statement has no effect [-Wunused-value]
  219 |         for(ind; ind < 4; ind++) if(B[ind] == a)
      |             ^~~
scales.cpp:265:13: warning: statement has no effect [-Wunused-value]
  265 |         for(ind; ind < 5; ind++) if(B[ind] == a)
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...