답안 #352099

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
352099 2021-01-20T12:22:16 Z Sprdalo 콤보 (IOI18_combo) C++17
컴파일 오류
0 ms 0 KB
#include "combo.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

string pass;
int N, cnt;
int press(string s){
    ++cnt;
    int n = N, m = s.length();

    if (m > 4*n || m<0) throw SIGSEGV;

    int sol = 0;
    for (int i = 0; i < m; ++i){
        int r = 0, ind = i;
        for (int j = 0; j < n; ++j){
            if (s[ind] == pass[j]){
                ++r;
                ++ind;
            } else {
                sol = max(sol, r);
                break;
            }
        }
    }

    return sol;
}

string guess_sequence(int n){
    int k = press("AB");

    char d;
    if (!k){
        k = press("X");
        if (!k)
            d = 'Y';
        else
            d = 'X';
    } else {
        k = press("A");
        if (!k)
            d = 'B';
        else
            d = 'A';
    }

    string st = "ABXY";
    if (d == 'A')
        st = "BXY";
    else if (d == 'B')
        st = "AXY";
    else if (d == 'X')
        st = "ABY";
    else
        st = "ABX";

    char a = st[0], b = st[1], c = st[2];

    string s = "";
    s += d;

    for (int i = 2; i < n; ++i){
        string t = "";
        t += (s + a + a);
        t += (s + a + b);
        t += (s + a + c);
        t += (s + b);

  //      cout << "PITAM " << t << ' ';
        k = press(t);
    //    cout << k << '\n';

        if (k == i-1){
            s += c;
            continue;
        }

        if (k == i){
            s += b;
            continue;
        }

        s += a;
    }

    k = press(s+a);
    if (k == n){
        s += a;
        return s;
    }
    
    k = press(s+b);
    if (k == n){
        s += b;
        return s;
    }

    s += c;
    return s;
}


signed man()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    

    cin >> pass;

    N = pass.length();

    cout << guess_sequence(N) << '\n';
    cout << N << ' ' <<  cnt << '\n';
}

Compilation message

combo.cpp: In function 'int man()':
combo.cpp:131:1: warning: no return statement in function returning non-void [-Wreturn-type]
  131 | }
      | ^
/usr/bin/ld: /tmp/ccb2cpiB.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/ccWmQK6A.o:combo.cpp:(.text+0xc0): first defined here
collect2: error: ld returned 1 exit status