제출 #987557

#제출 시각아이디문제언어결과실행 시간메모리
987557cig32Flight to the Ford (BOI22_communication)C++17
0 / 100
3264 ms3408 KiB
#include"communication.h" #include "bits/stdc++.h" using namespace std; // // --- Sample implementation for the task communication --- // // To compile this program with the sample grader, place: // communication.h communication_sample.cpp sample_grader.cpp // in a single folder, then open the terminal in this directory (right-click onto an empty spot in the directory, // left click on "Open in terminal") and enter e.g.: // g++ -std=c++17 communication_sample.cpp sample_grader.cpp // in this folder. This will create a file a.out in the current directory which you can execute from the terminal // as ./a.out // See task statement or sample_grader.cpp for the input specification // void encode(int N, int X) { int a[4] = {0, 6, 9, 15}; vector<pair<int,int>> r; r.push_back({1, N}); int itrs=0; while(1) { itrs++; int ts = 0; for(auto x: r) ts += x.second - x.first + 1; if(ts <= 2) break; vector<pair<int,int>> A[4]; int cap[4] = {ts/4, ts/4, ts/4, ts - 3 * (ts/4)}; for(int i=0; i<4; i++) { int sum = 0; for(int j=0; j<r.size(); j++) { sum += r[j].second - r[j].first + 1; if(sum >= cap[i]) { int diff = sum - cap[i]; A[i].push_back({r[j].first, r[j].second - diff}); r[j].first = r[j].second - diff + 1; break; } else if(r[j].first <= r[j].second) { A[i].push_back({r[j].first, r[j].second}); r[j].first = 0; r[j].second = -1; } } } int actual; for(int j=0; j<4; j++) { bool yes = 0; for(auto x: A[j]) yes |= (x.first <= X && X <= x.second); if(yes) actual = j; } int got = 0; for(int i=0; i<4; i++) { int s = send((a[actual] & (1 << i)) ? 1 : 0); if(s) got |= (1 << i); } r.clear(); for(int i=0; i<4; i++) { int bruh = a[i] ^ got; bool bits[4]; for(int j=0; j<4; j++) bits[j] = ((bruh & (1 << j)) ? 1 : 0); bool bad = 0; for(int j=0; j<3; j++) bad |= (bits[j+1] == bits[j] && bits[j] == 1); if(bad) continue; for(auto x: A[i]) r.push_back(x); } } } std::pair<int, int> decode(int N) { int a[4] = {0, 6, 9, 15}; vector<pair<int,int>> r; r.push_back({1, N}); while(1) { int ts = 0; for(auto x: r) ts += x.second - x.first + 1; if(ts <= 2) break; vector<pair<int,int>> A[4]; int cap[4] = {ts/4, ts/4, ts/4, ts - 3 * (ts/4)}; for(int i=0; i<4; i++) { int sum = 0; for(int j=0; j<r.size(); j++) { sum += r[j].second - r[j].first + 1; if(sum >= cap[i]) { int diff = sum - cap[i]; A[i].push_back({r[j].first, r[j].second - diff}); r[j].first = r[j].second - diff + 1; break; } else if(r[j].first <= r[j].second) { A[i].push_back({r[j].first, r[j].second}); r[j].first = 0; r[j].second = -1; } } } int got = 0; for(int i=0; i<4; i++) { int s = receive(); if(s) got |= (1 << i); } r.clear(); for(int i=0; i<4; i++) { int bruh = a[i] ^ got; bool bits[4]; for(int j=0; j<4; j++) bits[j] = ((bruh & (1 << j)) ? 1 : 0); bool bad = 0; for(int j=0; j<3; j++) bad |= (bits[j+1] == bits[j] && bits[j] == 1); if(bad) continue; for(auto x: A[i]) r.push_back(x); } } vector<int> ss; for(auto x: r) { for(int i=x.first; i<=x.second; i++) ss.push_back(i); } if(ss.size() == 2) { return {ss[0], ss[1]}; } else { return {ss[0], ss[0]}; } } /* g++ -std=c++17 -O2 -o T2442 sample_grader.cpp T2442.cpp ./T2442 < input.txt */

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

communication.cpp: In function 'void encode(int, int)':
communication.cpp:30:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |       for(int j=0; j<r.size(); j++) {
      |                    ~^~~~~~~~~
communication.cpp: In function 'std::pair<int, int> decode(int)':
communication.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |       for(int j=0; j<r.size(); j++) {
      |                    ~^~~~~~~~~
communication.cpp: In function 'void encode(int, int)':
communication.cpp:54:29: warning: 'actual' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |       int s = send((a[actual] & (1 << i)) ? 1 : 0);
      |                     ~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...