QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#697446#6440. Xingqiu's Jokefsy_juruo#WA 262ms21324kbC++173.2kb2024-11-01 14:07:072024-11-01 14:07:08

Judging History

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

  • [2024-11-01 14:07:08]
  • 评测
  • 测评结果:WA
  • 用时:262ms
  • 内存:21324kb
  • [2024-11-01 14:07:07]
  • 提交

answer

#include <bits/stdc++.h>

int T, a, b;
int d[3000], p[15], divs[3000];
std::unordered_map<int, int> d1, d2;
int f[3000][1500];

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> T;
    while(T--) {
        std::cin >> a >> b;
        if(a > b) std::swap(a, b);
        if(b - a == 1) {
            std::cout << a - 1 << "\n";
        } else {
            int delta = b - a, dd = delta, pi = 0, cnt = 0;
            for(int i = 2; i <= sqrt(dd); i++) {
                if(dd % i == 0) {
                    p[++pi] = i;
                    while(dd % i == 0) dd /= i;
                }
            }
            if(dd > 1) p[++pi] = dd;
            for(int i = 1; i <= sqrt(delta); i++) {
                if(delta % i == 0) {
                    d[++cnt] = i;
                    if(delta / i != i) d[++cnt] = delta / i;
                }
            }

            d1.clear();
            d2.clear();
            std::sort(d + 1, d + cnt + 1);
            for(int i = 1; i <= cnt; i++) {
                d2[d[i]] = i;
            }
            // int cnt1 = 0;
            // for(int i = cnt; i >= 1; i--) {
            //     int fl = a / d[i];
            //     int rg = a / d[i] + (a % d[i] != 0);
            //     if(fl && d1[fl] == 0) {
            //         ++cnt1;
            //         d1[fl] = cnt1;
            //         divs[cnt1] = fl;
            //     }
            //     if(rg && d1[rg] == 0) {
            //         ++cnt1;
            //         d1[rg] = cnt1;
            //         divs[cnt1] = rg;
            //     }
            //    // std::cout << fl << " " << rg << " " << d[i] << " " << cnt1 << "\n";
            // }

            memset(f, 0x7f, sizeof(f));
            f[1][0] = 0;
            for(int i = 1; i <= cnt; i++) {
                for(int j = 0; j <= 1; j++) {
                    int delt = delta / d[i];
                    if(a % d[i] == 0 && j) continue;
                    int res = a / d[i] + j;
                    for(int k = 1; k <= pi; k++) {
                        if(delta % p[k] == 0) {
                            int lf = res / p[k];
                            int rg = res / p[k] + (res % p[k] == 0);
                            int sta = a / (d[i] * p[k]);
                            int pos = d2[d[i] * p[k]];
                            if(lf != 0) {
                                f[pos][lf - sta] = std::min(f[pos][lf - sta], f[i][j] + res % p[k] + 1);
                            } 
                            if(rg != 0) {
                                f[pos][rg - sta] = std::min(f[pos][rg - sta], f[i][j] + p[k] - res % p[k] + 1);
                            }
                        }
                    }
                }
            }
            
            int ans = INT_MAX;
            for(int i = 1; i <= cnt; i++) {
                for(int j = 0; j <= 1; j++) {
                    if(a % d[i] == 0 && j) continue;
                    int res = a / d[i] + j;
                    if(res == 0) continue;
                    ans = std::min(ans, f[i][j] + res - 1);
                }
            }
            std::cout << ans << "\n";
        }
        
    }
    return 0;
}

详细

Test #1:

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

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: 262ms
memory: 21324kb

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:

-2146186522
-2147015438
-2144700043
-2146774669
-2147199287
-2147345474
-2142987670
-2147279161
-2146329963
-2147443636
-2144637831
-2142509148
-2146680876
-2145194674
-2147147839
-2147025704
-2146629394
-2143985551
-2145563591
-2147465955
-2147430870
-2146973207
-2146925013
-2145601548
-2146009281
...

result:

wrong answer 1st numbers differ - expected: '12', found: '-2146186522'