UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213288#3847. 分数约分18112606231502656ms1276kbC++112.9kb2024-11-10 11:54:012024-11-10 13:06:14

answer

#include <bits/stdc++.h>
#define int long long
#define MOD 1000000007
using namespace std;
int t, a, b, n, gcdd, minn, minx, shu[11], shuu[11], nowshu[11], nowshuu[11];
string s, ss;
bool xuan[21];
int stolll(string s)
{
    int res = 0;
    for (int i = 0; i < s.size(); i++)
    {
        res = res * 10 + s[i] - '0';
    }
    return res;
}
void dfs(int x)
{
    if (x == n)
    {
        string res = "";
        memset(nowshu, 0, sizeof(nowshu));
        memset(nowshuu, 0, sizeof(nowshuu));
        for (int i = 0; i < n; i++)
        {
            if (xuan[i])
            {
                res += s[i];
                nowshu[s[i] - '0']++;
            }
            //cout<<"res:"<<res<<endl;
        }
        //cout<<res<<endl;
        int num = stolll(res);
        if (num == 0)
            return;
        if (b * num % a != 0)
            return;
        num = b * num / a;
        string res2 = to_string(num),res3="";
        for(int i=0,j=0;i<res2.size(),j<ss.size();j++)
        {
            if(res2[i]==ss[j])
            {
                res3+=ss[j];
                i++;
            }
        }
        //cout << res << "/" << res2 << ' ' << a << '/' << b<<' '<<res3 << endl;
        if(res3!=res2)
            return;
        for (int i = 0; i < res2.size(); i++)
        {
            nowshuu[res2[i] - '0']++;
        }
        for (int i = 0; i < 10; i++)
        {
            //if(res=="670512")
                //cout<<shu[i]<<' '<<nowshu[i]<<' '<<shuu[i]<<' '<<nowshuu[i]<<endl;
            if (shu[i] - nowshu[i] < 0 || shuu[i] < nowshuu[i])
            {
                return;
            }
            if (shu[i] - nowshu[i] != shuu[i] - nowshuu[i])
            {
                return;
            }
        }
        int ans1 = stolll(res);
        int ans2 = stolll(res2);
        //cout<<ans1*b<<' '<<a*ans2<<endl;
        if (ans1 * b == a * ans2)
        {
            minn = min(minn, ans1);
            minx = min(minx, ans2);
        }
        return;
    }
    xuan[x] = true;
    dfs(x + 1);
    xuan[x] = false;
    dfs(x + 1);
}
signed main()
{
    scanf("%lld", &t);
    while (t--)
    {
        scanf("%lld %lld", &a, &b);
        memset(xuan, 0, sizeof(xuan));
        memset(shu, 0, sizeof(shu));
        memset(shuu, 0, sizeof(shuu));
        bool flag = false;
        if (a > b)
        {
            flag = true;
            swap(a, b);
        }
        minn = a, minx = b;
        s = to_string(a);
        ss = to_string(b);
        for (int i = 0; i < s.size(); i++)
        {
            shu[s[i] - '0']++;
        }
        for(int i = 0; i < ss.size(); i++)
        {
            shuu[ss[i] - '0']++;
        }
        n = s.size();
        dfs(0);
        if (!flag)
            printf("%lld %lld\n", minn, minx);
        else
            printf("%lld %lld\n", minx, minn);
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 5ms
memory: 1276kb

input:

10
295227892 738069730
21284157 63852471
312774536 781936340
82221828 68518190
167752458 55917486
90...

output:

295227892 738069730
21 63
31277456 78193640
822228 685190
167752458 55917486
904 7232
171 1197
24114...

result:

ok 20 numbers

Test #2:

score: 10
Accepted
time: 0ms
memory: 1268kb

input:

10
7231248 1807812
4301415 3441132
1931046 3862092
5184264 3240165
1144774 1717161
298584 2388672
87...

output:

324 81
4301415 3441132
193146 386292
518424 324015
1144774 1717161
298584 2388672
878 7902
370928 29...

result:

ok 20 numbers

Test #3:

score: 10
Accepted
time: 3ms
memory: 1272kb

input:

10
72320000 27120000
110000 11000000
90100000 9010000
270000 75600000
8230000 82300000
17910000 5970...

output:

32 12
1 100
10 1
2 560
2 20
171 57
893 94
60 6
7 70
434 620

result:

ok 20 numbers

Test #4:

score: 0
Wrong Answer
time: 3ms
memory: 1268kb

input:

10
6700512 10050768
6712050 10068075
7172058 10758087
9318720 13978080
71635224 107452836
71643522 1...

output:

670512 1005768
671250 1006875
717258 1075887
931872 1397808
71635224 107452836
71643522 107465283
71...

result:

wrong answer 9th numbers differ - expected: '3522', found: '71635224'

Test #5:

score: 10
Accepted
time: 588ms
memory: 1272kb

input:

10
44896548685746979 44896548685746979
76555658957975878 76555658957975878
9999998899899899 99999988...

output:

4 4
5 5
8 8
5 5
2 2
8 8
8 8
1 1
4 4
9 9

result:

ok 20 numbers

Test #6:

score: 10
Accepted
time: 360ms
memory: 1272kb

input:

10
5586978859946748 5586978859946748
5875932326322532 5875932326322532
7877997999879887 787799799987...

output:

4 4
2 2
7 7
9 9
4 4
6 6
8 8
4 4
7 7
4 4

result:

ok 20 numbers

Test #7:

score: 0
Wrong Answer
time: 273ms
memory: 1272kb

input:

10
163163163163163 326326326326326
163163111163111 326326222326222
142847142847 285714285714
2857142...

output:

11111 22222
163163111163111 326326222326222
142847142847 285714285714
285714 714285
8 4
432106661661...

result:

wrong answer 3rd numbers differ - expected: '111111111', found: '163163111163111'

Test #8:

score: 0
Wrong Answer
time: 993ms
memory: 1268kb

input:

10
142847114287112857 285714228574225714
142847111111112857 285714222222225714
142847111111111111 28...

output:

142847114287112857 285714228574225714
142847111111112857 285714222222225714
142847111111111111 28571...

result:

wrong answer 7th numbers differ - expected: '11111111111111111', found: '111111111111111110'

Test #9:

score: 0
Wrong Answer
time: 431ms
memory: 1268kb

input:

10
687069149440626451 336182506802090732
216198376277246428 246457923661369649
43706817238884428 372...

output:

687069149440626451 336182506802090732
216198376277246428 246457923661369649
43706817238884428 372089...

result:

wrong answer 13th numbers differ - expected: '111111111', found: '163163111163111'

Test #10:

score: 0
Time Limit Exceeded

input:

10
142847114247112857 285714228714225714
142847111111112857 285714222222225714
142847111111111111 28...

output:


result: