답안 #445899

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
445899 2021-07-20T05:50:43 Z aris12345678 Password (RMI18_password) C++14
0 / 100
0 ms 200 KB
// Sample grader for contestants' use.
//
// Usage: place your input data in the file password.in in the format
//
// line 1: N S
// line 2: hidden_password
//
// Then compile this grader together with your implementation.
// Run the binary to see your guessing strategy at work!
// Set DEBUG to 1 to print all queries.
#include <bits/stdc++.h>
using namespace std;

/*#define DEBUG 0
#define MAX_QUERIES 50000
#define MAX_N 5000
#define MAX_SIGMA 26

static string password;
static int n, s, numQueries;
static stringstream msg;

static void end(int success) {
  cout << (success ? "SUCCESS! " : "ERROR: ") << msg.str() << endl;
  exit(0);
}

int query(string q) {
  if (++numQueries > MAX_QUERIES) {
    msg << "Could not guess the password with " << MAX_QUERIES << " questions.";
    end(0);
  }

  int len = q.size();

  // validation
  if (len < 1 || len > n) {
    msg << "Query '" << q << "' should have length between 1 and "
        << n << " characters.";
    end(0);
  }

  for (int i = 0; i < len; i++) {
    if (q[i] < 'a' || q[i] >= 'a' + s) {
      msg << "Illegal character '" << q[i] << "' found.";
      end(0);
    }
  }

  // while possible, advance one character in q and find its next
  // occurrence in password
  int i = 0, j = 0, plen = password.size();
  while (i < plen && j < len) {
    while ((i < plen) && (password[i] != q[j])) {
      i++;
    }
    if (i < plen) {
      i++;
      j++;
    }
  }

  if (DEBUG) {
    cout << "Question #" << numQueries << " [" << q << "] answer " << j << endl;
  }
  return j;
}
*/
int query(string s);

string guess(int n, int s) {
  string alpha = "abcdefghijklmnopqrstuvwxyz";
  queue<string> q;
  for(int c = 0; c < s; c++) {
    string x = "";
    x += alpha[c];
    q.push(x);
  }
  while(!q.empty()) {
    string st = q.front();
    q.pop();
    if(query(st) == int(st.length())) {
      cout << st << " " << st.length() << " " << n << "\n";
      if(int(st.length()) == n)
        return st;
      for(int c = 0; c < s; c++)
        q.push(st+alpha[c]);
    }
  }
  assert(true);
}
/*
int main() {
  cin >> n >> s >> password;
  assert(n && s && !password.empty());

  string answer = guess(n, s);
  if (DEBUG) {
    cout << "Your answer: [" << answer << "]\n";
  }

  if (answer.compare(password)) {
    cout << "Your answer was [" << answer
        << "] which does not match the password [" << password << "].";
    end(0);
  } else {
    cout << "You guessed the password with " << numQueries << " queries.";
    end(1);
  }

	return 0;
}
*/

Compilation message

password.cpp: In function 'std::string guess(int, int)':
password.cpp:72:18: warning: control reaches end of non-void function [-Wreturn-type]
   72 |   string alpha = "abcdefghijklmnopqrstuvwxyz";
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 200 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 200 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 200 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 200 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 200 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -