제출 #590343

#제출 시각아이디문제언어결과실행 시간메모리
590343AlperenT저울 (IOI15_scales)C++17
71.43 / 100
711 ms420 KiB
#include <bits/stdc++.h> #include "scales.h" using namespace std; const int INF = 1e8 + 5; void init(int T) { /* ... */ } struct Rule{ int rt, x; vector<int> param; bool operator < (const Rule &sc) const{ return false; } }; vector<Rule> currules; bool finish; long double findcnt(){ int ans[3] = {}; vector<int> v; // if(finish) v = {5, 4, 3, 2, 1, 0}; // else v = {0, 1, 2, 3, 4, 5}; v = {0, 1, 2, 3, 4, 5}; do{ bool flag = true; for(int i = 0; i < (int)currules.size() - 1; i++){ if(!flag) break; auto rule = currules[i]; if(rule.rt == 1){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(min({v[a], v[b], v[c]}) == v[rule.x]) continue; else flag = false; } else if(rule.rt == 2){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(min({v[a], v[b], v[c]}) != v[rule.x] && max({v[a], v[b], v[c]}) != v[rule.x]) continue; else flag = false; } else if(rule.rt == 3){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(max({v[a], v[b], v[c]}) == v[rule.x]) continue; else flag = false; } else if(rule.rt == 4){ int a = rule.param[0], b = rule.param[1], c = rule.param[2], d = rule.param[3]; vector<int> v2; if(v[a] > v[d]) v2.push_back(a); if(v[b] > v[d]) v2.push_back(b); if(v[c] > v[d]) v2.push_back(c); if(v2.empty()){ if(min({v[a], v[b], v[c]}) == v[rule.x]) continue; else flag = false; } else{ int mn = INF; for(auto x : v2) mn = min(mn, v[x]); if(v[rule.x] == mn) continue; else flag = false; } } } if(flag){ Rule rule = currules[currules.size() - 1]; for(int i = 0; i < 3; i++){ rule.x = rule.param[i]; bool flag2 = true; if(rule.rt == 1){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(min({v[a], v[b], v[c]}) == v[rule.x]) goto skip; else flag2 = false; } else if(rule.rt == 2){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(min({v[a], v[b], v[c]}) != v[rule.x] && max({v[a], v[b], v[c]}) != v[rule.x]) goto skip; else flag2 = false; } else if(rule.rt == 3){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(max({v[a], v[b], v[c]}) == v[rule.x]) goto skip; else flag2 = false; } else if(rule.rt == 4){ int a = rule.param[0], b = rule.param[1], c = rule.param[2], d = rule.param[3]; vector<int> v2; if(v[a] > v[d]) v2.push_back(a); if(v[b] > v[d]) v2.push_back(b); if(v[c] > v[d]) v2.push_back(c); if(v2.empty()){ if(min({v[a], v[b], v[c]}) == v[rule.x]) goto skip; else flag2 = false; } else{ int mn = INF; for(auto x : v2) mn = min(mn, v[x]); if(v[rule.x] == mn) goto skip; else flag2 = false; } } skip: if(flag2) ans[i]++; } } }while(next_permutation(v.begin(), v.end())); int sum = 0, cnt = 0; for(int i = 0; i < 3; i++) if(ans[i] != 0) sum += ans[i], cnt++; // if(finish) cout << ans[0] << " " << ans[1] << " " << ans[2] << "\n"; return *max_element(ans, ans + 3); return cnt == 0 ? INF : (long double)sum / cnt; } void orderCoins(){ currules.clear();; vector<pair<long double, Rule>> posrules; while(true){ posrules.clear(); for(int t = 1; t <= 3; t++){ for(int a = 0; a < 6; a++){ for(int b = a + 1; b < 6; b++){ for(int c = b + 1; c < 6; c++){ currules.push_back({t, -1, {a, b, c}}); long double x = findcnt(); currules.pop_back(); posrules.push_back({x, {t, -1, {a, b, c}}}); } } } } for(int a = 0; a < 6; a++){ for(int b = a + 1; b < 6; b++){ for(int c = b + 1; c < 6; c++){ for(int d = 0; d < 6; d++){ if(a != d && b != d && c != d){ currules.push_back({4, -1, {a, b, c, d}}); long double x = findcnt(); currules.pop_back(); posrules.push_back({x, {4, -1, {a, b, c, d}}}); } } } } } auto p = *min_element(posrules.begin(), posrules.end()); if(p.first == 1){ auto rule = p.second; if(rule.rt == 1){ int x = getLightest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1); currules.push_back({1, x - 1, {rule.param[0], rule.param[1], rule.param[2]}}); } else if(rule.rt == 2){ int x = getMedian(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1); currules.push_back({2, x - 1, {rule.param[0], rule.param[1], rule.param[2]}}); } else if(rule.rt == 3){ int x = getHeaviest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1); currules.push_back({3, x - 1, {rule.param[0], rule.param[1], rule.param[2]}}); } else if(rule.rt == 4){ int x = getNextLightest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1, rule.param[3] + 1); currules.push_back({4, x - 1, {rule.param[0], rule.param[1], rule.param[2], rule.param[3]}}); } break; } else{ auto rule = p.second; if(rule.rt == 1){ int x = getLightest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1); currules.push_back({1, x - 1, {rule.param[0], rule.param[1], rule.param[2]}}); } else if(rule.rt == 2){ int x = getMedian(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1); currules.push_back({2, x - 1, {rule.param[0], rule.param[1], rule.param[2]}}); } else if(rule.rt == 3){ int x = getHeaviest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1); currules.push_back({3, x - 1, {rule.param[0], rule.param[1], rule.param[2]}}); } else if(rule.rt == 4){ int x = getNextLightest(rule.param[0] + 1, rule.param[1] + 1, rule.param[2] + 1, rule.param[3] + 1); currules.push_back({4, x - 1, {rule.param[0], rule.param[1], rule.param[2], rule.param[3]}}); } } } vector<int> v = {0, 1, 2, 3, 4, 5}; do{ bool flag = true; for(auto rule : currules){ if(!flag) break; if(rule.rt == 1){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(min({v[a], v[b], v[c]}) == v[rule.x]) continue; else flag = false; } else if(rule.rt == 2){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(min({v[a], v[b], v[c]}) != v[rule.x] && max({v[a], v[b], v[c]}) != v[rule.x]) continue; else flag = false; } else if(rule.rt == 3){ int a = rule.param[0], b = rule.param[1], c = rule.param[2]; if(max({v[a], v[b], v[c]}) == v[rule.x]) continue; else flag = false; } else if(rule.rt == 4){ int a = rule.param[0], b = rule.param[1], c = rule.param[2], d = rule.param[3]; vector<int> v2; if(v[a] > v[d]) v2.push_back(a); if(v[b] > v[d]) v2.push_back(b); if(v[c] > v[d]) v2.push_back(c); if(v2.empty()){ if(min({v[a], v[b], v[c]}) == v[rule.x]) continue; else flag = false; } else{ int mn = INF; for(auto x : v2) mn = min(mn, v[x]); if(v[rule.x] == mn) continue; else flag = false; } } } if(flag){ vector<pair<int, int>> ansv; for(int i = 0; i < 6; i++) ansv.push_back({v[i], i + 1}); sort(ansv.begin(), ansv.end()); int arr[6]; for(int i = 0; i < 6; i++) arr[i] = ansv[i].second; answer(arr); return; } }while(next_permutation(v.begin(), v.end())); }

컴파일 시 표준 에러 (stderr) 메시지

scales.cpp: In function 'void init(int)':
scales.cpp:8:15: warning: unused parameter 'T' [-Wunused-parameter]
    8 | void init(int T) {
      |           ~~~~^
scales.cpp: In member function 'bool Rule::operator<(const Rule&) const':
scales.cpp:17:34: warning: unused parameter 'sc' [-Wunused-parameter]
   17 |     bool operator < (const Rule &sc) const{
      |                      ~~~~~~~~~~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...