Submission #1054166

# Submission time Handle Problem Language Result Execution time Memory
1054166 2024-08-12T07:12:13 Z otarius Password (RMI18_password) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()

#define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

void open_file(string filename) {
    freopen((filename + ".in").c_str(), "r", stdin);
    freopen((filename + ".out").c_str(), "w", stdout);
}

// const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
// const int maxN;

int query(string s);

string merge(string a, string b) {
    int mx = query(b), i = 0;
    for (int j = 0; j <= b.size() && i < a.size(); j++) {
        string tmp = b; b.insert(b.begin() + j, a[i]);
        int now = query(b);
        if (now <= mx) b = tmp;
        else { mx = now; ++i; }
    } while (i < a.size()) b.pb(a[i++]);
    return b;
}
string guess(int n, int s) {
    deque<string> dq;
    for (int i = 0; i < s; i++) {
        string tmp = "";
        for (int j = 0; j < n; j++)
            tmp.pb(char('a' + i));
        cnt[i] = query(tmp);
        tmp.clear();
        for (int j = 0; j < cnt[i]; j++)
            tmp.pb(char('a' + i));
        dq.push_back(tmp);
    } while (dq.size() > 1) {
        string a = dq.back(); dq.pop_back();
        string b = dq.back(); dq.pop_back();
        dq.push_front(merge(a, b));
    } return dq.front();
}

Compilation message

password.cpp: In function 'std::string merge(std::string, std::string)':
password.cpp:41:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int j = 0; j <= b.size() && i < a.size(); j++) {
      |                     ~~^~~~~~~~~~~
password.cpp:41:40: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for (int j = 0; j <= b.size() && i < a.size(); j++) {
      |                                      ~~^~~~~~~~~~
password.cpp:46:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     } while (i < a.size()) b.pb(a[i++]);
      |              ~~^~~~~~~~~~
password.cpp: In function 'std::string guess(long long int, long long int)':
password.cpp:55:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
   55 |         cnt[i] = query(tmp);
      |         ^~~
      |         int
password.cpp: In function 'void open_file(std::string)':
password.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     freopen((filename + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
password.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((filename + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~