QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#717267#6440. Xingqiu's JokewenqizhiWA 602ms24524kbC++202.0kb2024-11-06 17:25:512024-11-06 17:25:51

Judging History

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

  • [2024-11-06 17:25:51]
  • 评测
  • 测评结果:WA
  • 用时:602ms
  • 内存:24524kb
  • [2024-11-06 17:25:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long

int read()
{
    int x = 0; bool f = false; char c = getchar();
    while(c < '0' || c > '9') f |= (c == '-'), c = getchar();
    while(c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c & 15), c = getchar();
    return f ? -x : x;
}

int p[25], cnt[25], tot, K;
map< pair<int, int> , int> mp;
int dfs(int a, int K)
{
    if(mp.count(pair<int, int>(a, K)) == 1) return mp[pair<int, int>(a, K)];
    if(K == 1 || a == 1) return a - 1;
    int ans = 0x7fffffff;
    for(int i = 1; i <= tot; ++i)
    {
        if(cnt[i] > 0)
        {
            int temp = a % p[i];
            if(a == temp){ ans = min(ans, temp - 1); continue; }
            // if(temp > p[i] - temp)
            // {
                --cnt[i];
                ans = min(ans, p[i] - temp + 1 + dfs((a + p[i] - temp) / p[i], K / p[i]));
                // ++cnt[i];
            // }else if(temp < p[i] - temp)
            // {
                // --cnt[i];
                ans = min(ans, temp + 1 + dfs((a - temp) / p[i], K / p[i]));
                ++cnt[i];
            // }else if(temp == p[i] - temp)
            // {
            //     --cnt[i];
            //     ans = min(ans, temp + 1 + dfs((a - temp) / p[i], K / p[i]));
            //     ans = min(ans, temp + 1 + dfs((a + temp) / p[i], K / p[i]));
            //     ++cnt[i];
            // }
        }
    }
    return mp[pair<int, int>(a, K)] = ans;
}

void solve()
{
    int a = read(), b = read(), x = abs(a - b), y = x, yy = sqrt(y);
    while(tot) p[tot] = cnt[tot] = 0, --tot;
    K = 0;
    for(int i = 2; i <= yy; ++i)
    {
        if(y % i == 0)
        {
            ++tot, p[tot] = i;
            while(y % i == 0) ++cnt[tot], y /= i, ++K;
        }
    }
    if(y > 1) ++tot, p[tot] = y, cnt[tot] = 1, ++K;
    printf("%d\n", dfs(min(a, b), x));
}

int main()
{
    int T = read();
    while(T--) solve();
    return 0;
}

詳細信息

Test #1:

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

input:

5
4 7
9 8
32 84
11 35
2 1

output:

2
7
5
4
0

result:

ok 5 number(s): "2 7 5 4 0"

Test #2:

score: -100
Wrong Answer
time: 602ms
memory: 24524kb

input:

300
223528529 446621399
755625805 978718675
257717538 480810408
277875777 54782907
963091558 739998688
282469431 505562301
38752451 261845321
474429597 697522467
67026335 290119205
874629705 651536835
301964126 78871256
316864911 93772041
545942587 322849717
640801578 417708708
683070559 906163429
9...

output:

12
19
15
17
16
17
13
19
15
17
15
15
18
17
17
19
14
18
15
16
17
18
19
15
17
17
17
12
19
17
12
19
16
15
13
18
17
18
16
15
14
17
14
16
15
14
19
18
16
14
16
17
16
18
14
16
17
16
18
17
16
19
19
18
17
17
16
14
23
14
14
18
18
20
16
16
17
17
12
18
19
17
16
18
16
15
18
12
15
18
16
12
19
18
15
18
17
14
13
16
...

result:

wrong answer 30th numbers differ - expected: '16', found: '17'