답안 #859816

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
859816 2023-10-10T17:52:01 Z Andrei_Calota Password (RMI18_password) C++17
0 / 100
2 ms 516 KB
#include <bits/stdc++.h>

using namespace std;
const int N_MAX = 5e3;
const int SIGMA_MAX = 26;

/**int query (string candidate) {
   cout << candidate << "\n";
   int ret; cin >> ret;
   return ret;
}**/

int query (string str);

string getCopy (int letter, int f) {
    string ret = "";
    for (int i = 0; i < f; i ++)
       ret = ret + char (letter + 'a');
    return ret;
}


int freq[SIGMA_MAX];
string guess (int n, int s) {

    int present;

    int N = n, SIGMA = s;
    string aux;
    for (int letter = 0; letter < SIGMA; letter ++) {
       aux = getCopy (letter, N);
       freq[letter] = query (aux);
       if (freq[letter] > 0)
         present ++;
    }

    string done = "";
    for (int pos = N - 1; pos >= 0 && present > 1; pos --) {
       int left = 0, right = 1;
       while (right < SIGMA) {
          if (freq[left] == 0) {
            left ++;
            right = max (right, left + 1);
            continue;
          }
          if (freq[right] == 0) {
            right ++;
            continue;
          }

          aux = getCopy (left, freq[left]);
          aux = aux + char (right + 'a');
          aux = aux + done;

          int len = query (aux);
          if (len == freq[left])
            right ++;
          else if (len != N) {
            left ++;
            right = max (left + 1, right);
          }
          else
            return aux;
       }
       done = char (left + 'a') + done;
       cout << "pana acum done este egal cu " << done << "\n";
       freq[left] --;
       if (freq[left] == 0)
         present --;
    }
    int missing = 0;
    while (missing < SIGMA && freq[missing] == 0)
       missing ++;
    done = getCopy (missing, freq[missing]) + done;
    return done;
}

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:69:18: warning: 'present' may be used uninitialized in this function [-Wmaybe-uninitialized]
   69 |          present --;
      |          ~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 432 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 432 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 516 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 432 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 432 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -