QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#121559#6407. Classical A+B ProblemSolitaryDream#WA 1ms3452kbC++201.7kb2023-07-08 14:16:112023-07-08 14:16:14

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-08 14:16:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3452kb
  • [2023-07-08 14:16:11]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
const int N=4005;
int a[N],b[N],c[N];
void solve() {
    string s;
    cin >> s;
    int n=s.size();
    FOR(i,0,n-1) a[i]=s[n-1-i]-'0';
    FOR(v,(n==1),9) {
        FOR(i,0,n-1) b[i]=v;
        int x=0;
        FOR(i,0,n-1) {
            x+=a[i]-b[i];
            if(x<0) {
                c[i]=x+10;
                x=-1;
            } else {
                c[i]=x;
                x=0;
            }
        }
        if(x<0) continue;
        int p=n;
        while(p && c[p-1]==0) --p;
        if(p) {
            int w=1;
            FOR(i,0,p-2) if(c[i]!=c[p-1]) w=0;
            if(w) {
                FOR(i,0,n-1) cout << b[i];
                cout << ' ';
                FOR(i,0,p-1) cout << c[i];
                cout << '\n';
                return ;
            }
        }
    }
    FOR(v,(n==2),9) {
        FOR(i,0,n-2) b[i]=v;
        b[n-1]=0;
        int x=0;
        FOR(i,0,n-1) {
            x+=a[i]-b[i];
            if(x<0) {
                c[i]=x+10;
                x=-1;
            } else {
                c[i]=x;
                x=0;
            }
        }
        if(x<0) continue;
        int p=n;
        while(p && c[p-1]==0) --p;
        if(p) {
            int w=1;
            FOR(i,0,p-2) if(c[i]!=c[p-1]) w=0;
            if(w) {
                FOR(i,0,n-2) cout << b[i];
                cout << ' ';
                FOR(i,0,p-1) cout << c[i];
                cout << '\n';
                return ;
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3452kb

input:

6
2
786
1332
89110
2333333
10000000000000000000000000001

output:

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

result:

ok ok (6 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3416kb

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:

777 77
77777777777777777777777777777 3333333333333333333
44444444 6
11111111111111111 222
2222 88
1 4
333333333333333333333333333 9999
888888 111
1 9
11111111 2222
333 2
77777 2
88888888888888888888888888888888888888888888 222222222222222222222
55555555555555555555 222222
66666666666666666666666 555...

result:

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