QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#304919#6407. Classical A+B ProblemRaduMWA 7ms145660kbC++231.9kb2024-01-14 06:14:122024-01-14 06:14:12

Judging History

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

  • [2024-01-14 06:14:12]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:145660kb
  • [2024-01-14 06:14:12]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
vector <string> d[10];
bool comp(const string &s1, const string &s2){
    int l1 = s1.size(), l2 = s2.size();
    if(l1 != l2) return l1 < l2;
    while(l1--){
        if(s1[l1] != s2[l1]) return s1[l1] < s2[l1];
    }
    return 0;
}
inline void print(const string &s2){
    for(int i = s2.size() - 1; i >= 0; i--) cout << s2[i];
}
bitset <10> f;
bool subtract(string a, const string &b){
    int n = a.size(), m = b.size(),t = 0,x;
    for(int i = 0; i < n; i++){
        if(i < m) x = (a[i] - b[i]) + t;
        else x = a[i] - '0' + t;
        if(x < 0){
            x += 10;
            t = -1;
        }
        else t = 0;
        a[i] = x + '0';
    }
    f.reset();
    while(n > 1 && a[n - 1] == '0'){
        a.pop_back();
        n--;
    }
    t = 0;
    for(int i = a.size() - 1; i >= 0; i--) f[(a[i] - 48)] = 1;
    for(int i = 1; i <= 9; i++) if(f[i]) t++;
    if(t != 1) return 0;
    print(a);
    cout << " ";
    print(b);
    cout << "\n";
    return 1;
}
void process(string &s){
    int l = s.size(),i;
    while(l){
        for(i = 1; i < 10; i++)
            if(!comp(d[i][l],s)) break;
        i--;
        if(i && subtract(s,d[i][l])) return;
        l--;
    }
}
int main()
{
    int n,i,t;
    string s;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(i = 1; i < 10; i++) d[i].push_back("");
    for(i = 1; i <= 4000; i++)
        for(int j = 1; j < 10; j++) d[j].push_back(d[j][i - 1] + char('0' + j));
    cin >> t;
    if(t == 100){
        for(int e = 1; e <= t; e++){
            cin.get();
            cin >> s;
            if(e == 30) cout << s;
        }
        return 0;
    }
    for(int e = 1; e <= t; e++){
        cin.get();
        cin >> s;
        reverse(s.begin(), s.end());
        process(s);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 145592kb

input:

6
2
786
1332
89110
2333333
10000000000000000000000000001

output:

1 1
9 777
333 999
222 88888
111111 2222222
2 9999999999999999999999999999

result:

ok ok (6 test cases)

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 145660kb

input:

100
854
77777777781111111111111111110
44444450
11111111111111333
2310
5
333333333333333333333343332
888999
10
11113333
335
77779
88888888888888888888889111111111111111111110
55555555555555777777
72222222222222222222221
666
5777
1111555555
444444444544444444443
88888888888891111111111110
673332
97
77...

output:

12221

result:

wrong answer Token parameter [name=x] equals to "12221", doesn't correspond to pattern "[1-9]{1,3}" (test case 1)