QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#132479#6407. Classical A+B Problemcciafrino#WA 1ms3512kbC++141.9kb2023-07-30 00:12:402023-07-30 00:12:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-30 00:12:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3512kb
  • [2023-07-30 00:12:40]
  • 提交

answer

#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2")
#include <bits/stdc++.h>

using namespace std;

string sub(const string& s1, const string& s2) {
    int N = int(s1.size());
    string res(s1.size(), '0');
    int emprestimo = 0;
    int last_nn = -1;
    for(int i=0; i<(int)s1.size(); i++) {
        int n1 = s1[s1.size()-1 - i] - emprestimo - '0';
        char aux;
        if(((int) s2.size()) - i > 0) {
            int n2 = s2[((int) s2.size())-1 - i] - '0';
            aux = ((n1-n2 + 10) % 10) + '0';
            emprestimo = (n1-n2) < 0 ? 1 : 0;
            // cout << i << " . " << n1 << " " << n2 << " " << aux << " " << emprestimo << endl;
        } else {
            emprestimo = 0;
            aux = n1 + '0';
            // cout << i << " # " << n1 << " " << aux << " " << emprestimo << endl;
        }
        // cout << last_nn << endl;
        if (aux > '0') last_nn = res.size() - i - 1;
        res[res.size()-1 - i] = aux;
    }
    
    return string(res.begin() + last_nn, res.end());
}

bool check(const string& b) {
    char c = b[b.size()-1];
    for (int i = 0; i < int(b.size())-1; ++i) {
        if (b[i] != c) return false;
    }
    return true;
}

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

    int T; cin >> T;

    while (T--) {
        string S; cin >> S;
        
        bool flag = true;
        for(int i=S.size() && flag; i>=1; i--) {
            for(char c='1'; c<='9' && flag; c++) {
                string a = string(i, c);
                if(S < a) continue;
                string b = sub(S, a);
                // cout << a << " " << b << " " << S << endl;
                
                if(check(b)){ 
                    cout <<  a << " " << b << '\n';
                    flag = false;
                }
            }
        }
    }

    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3512kb

input:

6
2
786
1332
89110
2333333
10000000000000000000000000001

output:

1 1

result:

wrong output format Unexpected end of file - token expected (test case 2)