QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#688056#6440. Xingqiu's JokeKopicyWA 1881ms3928kbC++231.5kb2024-10-29 23:02:262024-10-29 23:02:27

Judging History

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

  • [2024-10-29 23:02:27]
  • 评测
  • 测评结果:WA
  • 用时:1881ms
  • 内存:3928kb
  • [2024-10-29 23:02:26]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define rep(i, a, b) for(int i=(a);i<=(b);++i)
#define sz(x) (int)x.size()
#define endl "\n"
const int N = 2e5, mod = 1e9 + 7, inf = 1e18;

vector<int> p;
int vis[40005];

void solve() {
    int n,m;
    cin>>n>>m;
    auto get=[&](int d){
        vector<int> tmp;
        for(int x:p){
            if(x*2>d) break;
            if(d%x==0)
            tmp.push_back(x);
        }
        if(tmp.empty()) tmp.push_back(d);
        return tmp;
    };
    map<array<int,2>,int> mp;
    function<int(int,int)> dfs=[&](int n,int m){
        int d=abs(n-m);
        if(n==1 || m==1) return 0LL;
        if(d==1) return min(n,m)-1;
        if(mp.count({n,m})) return mp[{n,m}];
        vector<int> tmp=get(d);
        int res=inf;
        for(auto x:tmp){
            if(n%x){
                int ad=n%x;
                if(ad>=100) continue;
                if(n!=ad && m!=ad) res=min(res,1+ad+dfs((n-ad)/x,(m-ad)/x));
                res=min(res,1+x-ad+dfs((n+x-ad)/x,(m+x-ad)/x));
            }
            else{
                res=min(res,1+dfs(n/x,m/x));
            }
        }
        mp[{n,m}]=res;
        return res;
    };

    cout<<dfs(n,m)<<'\n';
}

signed main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    rep(i,2,40000){
        if(vis[i]) continue;
        p.push_back(i);
        for(int j=2;j*i<=40000;j++) vis[i*j]=1;
    }
    int tt = 1;
    cin >> tt;
    rep(kase, 1, tt) solve();
}

详细

Test #1:

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

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: 1881ms
memory: 3912kb

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
16
18
17
17
19
16
18
15
16
17
18
19
15
17
17
17
13
19
16
13
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
14
18
17
16
19
19
18
17
16
16
14
23
14
14
18
18
20
16
16
17
17
12
18
19
17
16
18
16
17
18
12
15
18
16
13
19
18
16
18
17
15
13
16
...

result:

wrong answer 12th numbers differ - expected: '15', found: '16'