QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#824988#9768. A + B = C Problemucup-team5243#RE 0ms3524kbC++172.7kb2024-12-21 16:52:012024-12-21 16:52:06

Judging History

This is the latest submission verdict.

  • [2024-12-21 16:52:06]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3524kb
  • [2024-12-21 16:52:01]
  • Submitted

answer

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
using namespace std;

string trans(string a, string b, string c){
    string res;
    for(char x : a){
        if(x == '0') res += b;
        else res += c;
    }
    return res;
}

vector<string> solve(i64 a, i64 b, i64 c){
    if(b > c){
        auto X = solve(a,c,b);
        if(X.empty()) return {};
        return { X[0], X[2], X[1] };
    }
    if(a > c){
        auto X = solve(c,b,a);
        if(X.empty()) return {};
        return { X[2], X[1], X[0] };
    }
    vector<string> ans;
    {
        i64 g = gcd(gcd(a,b), c);
        if(g != 1){
            auto X = solve(a/g, b/g, c/g);
            ans.push_back(trans(X[0], "01", "10"));
            ans.push_back(trans(X[1], "01", "10"));
            ans.push_back(trans(X[2], "00", "11"));
            return ans;
        }
    }
    rep(t,3) ans.push_back("0");
    rep(t,3){
        if(a != gcd(a,b) * gcd(a,c)) return {};
        i64 g = gcd(a,b);
        if(g != 1){
            //string F = string(g, '0'); F[g-1] = '1';
            //string G = string(g, '1'); G[g-1] = '0';
            auto x = ans[0];
            auto y = ans[1];
            rep(i,g-1) ans[0] += x;
            rep(i,g-1) ans[1] += y;
            rep(s,2) rep(i,ans[s].size()) if(i % g == 0) ans[s][i] ^= '0' ^ '1';
        }
        swap(ans[0], ans[1]); swap(ans[1], ans[2]);
        swap(a,b); swap(b,c);
    }
    return ans;
}

void testcase(){
    i64 a,b,c; cin >> a >> b >> c;
    if(a == b && b == c){
        if(a == 2){
            cout << "NO\n";
            return;
        }
        if(a == 1){
            cout << "YES\n0\n0\n0\n";
            return;
        }
        cout << "YES\n";
        rep(i,a){
            cout << (i == 0 ? "1" : "0");
        } cout << "\n";
        rep(i,a){
            cout << (i == 1 ? "1" : "0");
        } cout << "\n";
        rep(i,a){
            cout << (i <= 1 ? "1" : "0");
        } cout << "\n";
        return;
    }
    auto ans = solve(a,b,c);
    if(ans.empty()){
        cout << "NO\n";
    } else {
        cout << "YES\n";
        rep(t,3) cout << ans[t] << "\n";
    }
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    i64 T; cin >> T;
    rep(t,T)
    testcase();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3524kb

input:

2
2 3 6
2 3 5

output:

YES
10
100
001110
NO

result:

ok ok (2 test cases)

Test #2:

score: -100
Runtime Error

input:

1214
940 746 485
304 504 661
815 674 830
704 774 691
545 597 924
330 894 320
491 425 479
768 869 698
706 480 785
358 548 504
999 473 363
532 950 745
512 682 364
829 832 959
570 931 317
324 543 362
590 421 737
326 483 503
958 890 793
836 721 518
720 361 363
730 402 753
810 416 585
781 953 490
623 360...

output:


result: