제출 #1104881

#제출 시각아이디문제언어결과실행 시간메모리
1104881monaxia콤보 (IOI18_combo)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
// #include "combo.h"
#define pb push_back
#define ppb pop_back
#define fr first
#define sc second
#define all(v) v.begin(), v.end()
#define eps (long long)(1e-9)

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;

const ll Mod = 1e9 + 7;

string S = "YB";
int N = S.size();

int press(string p) {
  int coins = 0;
  int len = p.length();

  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 = max(coins, j);
  }
  return coins;
}

string guess_sequence(int n){
    string ans = "", temp = "ABXY";
    char ex = 'S';
    int cnt = 0;

    for(int i = 0; i < 3; i ++){
        char x = temp[i];

        ans.pb(x);
        if(press(ans) > cnt){
            cnt ++;
            break;
        }

        ans.ppb();
    }

    if(!cnt) ex = 'Y', cnt ++, ans.pb('Y');
    else ex = ans[0];

    string newtemp = "";

    for(auto& x : temp) if(x != ex) newtemp.pb(x);

    while(cnt != n){
        bool yeye = 0;
        for(int i = 0; i < 2; i ++){
            char x = newtemp[i];

            ans.pb(x);
            if(press(ans) > cnt){
                yeye = 1;
                cnt ++;
                break;
            }

            ans.ppb();
        }

        if(!yeye) ans.pb(newtemp[2]), cnt ++; 
    }

    return ans;
}   

void solve(){
    cout << guess_sequence(S.size());
}

signed main()
{
    cin.tie(0)->sync_with_stdio(0);
 
    if(fopen("blank.inp", "r")){
        freopen("blank.inp", "r", stdin);
        freopen("blank.out", "w", stdout);
    }
    
    // cout << 1; return 0;

    ll n = 1;

    // cin >> n;

    while(n) {
        solve();
        n --;
        cout << "\n";
    }
 
    // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}

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

combo.cpp: In function 'int main()':
combo.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen("blank.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
combo.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen("blank.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/cctd5ZAw.o: in function `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
grader.cpp:(.text+0x0): multiple definition of `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'; /tmp/cc9ggpTt.o:combo.cpp:(.text+0xc0): first defined here
/usr/bin/ld: /tmp/cctd5ZAw.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc9ggpTt.o:combo.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status