답안 #947099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947099 2024-03-15T13:47:51 Z steveonalex 콤보 (IOI18_combo) C++14
5 / 100
1 ms 344 KB
#include <bits/stdc++.h>
#include "combo.h"

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1ULL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

// namespace Interactor{
//     int n;
//     string a;
//     int query_cnt;
//     int press(string p){
//         query_cnt++;
//         int ans = 0;
//         for(int i= 0; i<p.size(); ++i){
//             int cnt = 0;
//             for(int j = 0; i + j < p.size() && j < a.size(); ++j){
//                 if (p[i+j] == a[j])cnt++;
//                 else break;
//                 maximize(ans, cnt);
//             }
//         }
//         // cout << "? " << p << "\n";
//         // cout << "-> " << ans << "\n";
//         return ans;
//     }

    char pool[] = {'A', 'B', 'X', 'Y'};
    string guess_sequence(int n){
        int l = 0, r = 3;
        while(l < r){
            int mid = (l + r) >> 1;
            string p;
            for(int i = 0; i<=mid; ++i) p.push_back(pool[i]);
            if (press(p) >= 1) r = mid;
            else l = mid + 1;
        }
        string ans = string(1, pool[l]);
        vector<int> hot;
        for(int i= 0; i<4; ++i) if (i != l) hot.push_back(i);
        for(int i = 2; i<n; ++i){
            string a = ans + string(1, pool[hot[0]]);
            string b = ans + string(1, pool[hot[1]]);
            string p = a;
            for(int j: hot) p += b + string(1, pool[j]);


            int verdict = press(p);
            if (verdict == i-1){
                ans += string(1, pool[hot[2]]);
            }
            else if (verdict == i) {
                ans += string(1, pool[hot[0]]);
            }
            else if (verdict == i + 1) ans += string(1, pool[hot[1]]);

            if (i <= 2000 && press(ans) != ans.size()) exit(1);
        }
        for(int i:hot){
            if (i != hot.back()) {
                if (press(ans + string(1, pool[i])) == n){
                    ans.push_back(pool[i]);
                    break;
                }
            }
            else ans.push_back(pool[i]);
        }
        return ans;
    }

//     bool solve(int _n, string _a){
//         query_cnt = 0;
//         n = _n; a = _a;
//         string b = guess_sequence(n);
//         cout << "? " << a << "\n";
//         cout << "! " << b << "\n";
//         return a == b;
//     }
// }

//     char pool[] = {'A', 'B', 'X', 'Y'};
// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int n; cin >> n;
//     int t = 100;
//     while(t--){
//         string a;
//         int s = rngesus(0, 3);
//         a.push_back(pool[s]);
//         vector<int> hot;
//         for(int i = 0; i<4; ++i) if (i != s) hot.push_back(i);
//         for(int i = 1; i<n; ++i) a.push_back(pool[hot[rngesus(0, 2)]] );

//         bool verdict = Interactor::solve(n, a);
//         if (verdict) cout << "AC\n";
//         else cout << "WA\n";

//         if (verdict == false) break;
//     }

//     return 0;
// }

Compilation message

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:97:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |             if (i <= 2000 && press(ans) != ans.size()) exit(1);
      |                              ~~~~~~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 344 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 0 ms 344 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer: wrong guess.
2 Halted 0 ms 0 KB -