QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#850318#9768. A + B = C ProblemciuimCompile Error//C++141.8kb2025-01-10 00:41:412025-01-10 00:41:42

Judging History

你现在查看的是最新测评结果

  • [2025-01-10 00:41:42]
  • 评测
  • [2025-01-10 00:41:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;

#define all(a) begin(a), end(a)
#define len(a) int((a).size())

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename T>
std::vector<int> prefix_function(const T &str) {
    int n = str.size();
    std::vector<int> p(n);
    for (int i = 1, j = 0; i < n; i++) {
        while (j > 0 && str[i] != str[j]) {
            j = p[j - 1];
        }
        if (str[i] == str[j]) {
            j++;
        }
        p[i] = j;
    }
    return p;
}

int period(const string &s) {
    int p = len(s) - prefix_function(s).back();
    return len(s) % p == 0 ? p : len(s);
}

void update(string &A, string &B, ll g) {
    vector<int> m(g);
    for (auto &x : m) {
        x = rng() % 2;
    }
    for (int i = 0; i < len(A); i++) {
        A[i] ^= m[i % g];
    }
    for (int i = 0; i < len(B); i++) {
        B[i] ^= m[i % g];
    }
}

void solve(int /* test_num */) {
    ll a, b, c;
    cin >> a >> b >> c;
    string A(a, '0'), B(b, '0'), C(c, '0');
    ll gab = gcd(a, b), gbc = gcd(b, c), gca = gcd(c, a);
    if(c==a*b/gab||a==b*c/gbc||b==a*c/gca) ;
    else
    {
    	cout<<"NO\n";
    	return;
	}
    for (int it = 0; it < 40; it++) {
        if (period(A) == a && period(B) == b && period(C) == c) {
            cout << "Yes\n" << A << '\n' << B << '\n' << C << '\n';
            return;
        }
        update(A, B, gab);
        update(B, C, gbc);
        update(C, A, gca);
    }
    cout << "NO\n";
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int tests;
    cin >> tests;
    for (int test_num = 1; test_num <= tests; test_num++) {
        solve(test_num);
    }
}

Details

answer.code: In function ‘void solve(int)’:
answer.code:50:14: error: ‘gcd’ was not declared in this scope
   50 |     ll gab = gcd(a, b), gbc = gcd(b, c), gca = gcd(c, a);
      |              ^~~
answer.code:51:27: error: ‘gbc’ was not declared in this scope
   51 |     if(c==a*b/gab||a==b*c/gbc||b==a*c/gca) ;
      |                           ^~~
answer.code:51:39: error: ‘gca’ was not declared in this scope
   51 |     if(c==a*b/gab||a==b*c/gbc||b==a*c/gca) ;
      |                                       ^~~
answer.code:63:22: error: ‘gbc’ was not declared in this scope
   63 |         update(B, C, gbc);
      |                      ^~~
answer.code:64:22: error: ‘gca’ was not declared in this scope
   64 |         update(C, A, gca);
      |                      ^~~