제출 #428455

#제출 시각아이디문제언어결과실행 시간메모리
428455ivan24콤보 (IOI18_combo)C++14
0 / 100
1 ms256 KiB
#include "combo.h" #include <bits/stdc++.h> using namespace std; using ll = long long int; typedef vector<ll> vi; typedef pair<ll,ll> ii; typedef vector<ii> vii; typedef vector<vi> vvi; #define F first #define S second ll min(ll x, ll y){ return ((x < y) ? x : y); } ll max(ll x, ll y){ return ((x > y) ? x : y); } /* namespace { constexpr int MAX_N = 2000; constexpr int MAX_NUM_MOVES = 8000; int N; std::string S; int num_moves; void wrong_answer(const char *MSG) { printf("Wrong Answer: %s\n", MSG); exit(0); } } // namespace int press(std::string p) { if (++num_moves > MAX_NUM_MOVES) { wrong_answer("too many moves"); } int len = p.length(); if (len > 4 * N) { wrong_answer("invalid press"); } for (int i = 0; i < len; ++i) { if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') { wrong_answer("invalid press"); } } int coins = 0; for (int i = 0, j = 0; i < len; ++i) { if (j < N && S[j] == p[i]) { ++j; } else if (S[0] == p[i]) { j = 1; } else { j = 0; } coins = std::max(coins, j); } return coins; } int main() { char buffer[MAX_N + 1]; if (scanf("%s", buffer) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } S = buffer; N = S.length(); num_moves = 0; std::string answer = guess_sequence(N); if (answer != S) { wrong_answer("wrong guess"); exit(0); } printf("Accepted: %d\n", num_moves); return 0; } //*/ class Solver{ private: string outp; ll n; void getFirstChar(){ ll res = press("AB"); if (res == 2) outp = "AB"; else if (res == 1){ res = press("A"); if (res == 1) outp = "A"; else outp = "B"; }else{ res = press("C"); if (res == 1) outp = "C"; else outp = "D"; } } public: Solver(ll n): n(n){ getFirstChar(); vector<char> ogchoices = {'A','B','X','Y'}; vector<char> choices; for (auto c: ogchoices){ if (c != outp[0]) choices.push_back(c); } while (outp.size() < n){ bool found = false; for (ll i = 0; 2 > i; i++){ string query = outp; query.push_back(choices[i]); ll res = press(query); if (res == query.size()){ found = true; outp.push_back(choices[i]); break; } } if (!found){ outp.push_back(choices[2]); } } } string solve(){ //cout << outp << endl; return outp; } }; std::string guess_sequence(int n) { Solver solver(n); return solver.solve(); }

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

combo.cpp: In constructor 'Solver::Solver(ll)':
combo.cpp:113:28: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
  113 |         while (outp.size() < n){
      |                ~~~~~~~~~~~~^~~
combo.cpp:119:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  119 |                 if (res == query.size()){
      |                     ~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...