QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#666040#6440. Xingqiu's Jokecomp_towels_catWA 1063ms104968kbC++173.4kb2024-10-22 16:22:532024-10-22 16:23:17

Judging History

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

  • [2024-10-22 16:23:17]
  • 评测
  • 测评结果:WA
  • 用时:1063ms
  • 内存:104968kb
  • [2024-10-22 16:22:53]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define int long long
#define FOR(i, j, k) for(int i = (j);i <= (k);i ++)
#define ROF(i, j, k) for(int i = (j);i >= (k);i --)
#define For(i, j, k) for(int i = (j);i < (k);i ++)
#define Rof(i, j, k) for(int i = (j);i > (k);i --)
#define ull unsigned long long
#define PII pair<int,int>
#define ULL unsigned long long
#define db double
#define x first
#define y second
#define sp(x) fixed << setprecision(x)
#define all(x) x.begin(), x.end()
#define unq_all(x) x.erase(unique(all(x)), x.end())
#define M(x) x %= mod, x += mod, x %= mod
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define ANS cout << ans << '\n'
#define de(p) cout << #p << ' ' << p << '\n'
#define END(i, n) (i == n ? '\n' : ' ')
#define double long double

#define RED cout << "\033[91m"
#define GREEN cout << "\033[92m"
#define YELLOW cout << "\033[93m"
#define BLUE cout << "\033[94m"
#define MAGENTA cout << "\033[95m"
#define CYAN cout << "\033[96m"
#define RESET cout << "\033[0m"

// 红色
#define DEBUG1(x)                     \
    RED;                              \
    cout << #x << " : " << x << endl; \
    RESET;

// 绿色
#define DEBUG2(x)                     \
    GREEN;                            \
    cout << #x << " : " << x << endl; \
    RESET;

// 蓝色
#define DEBUG3(x)                     \
    BLUE;                             \
    cout << #x << " : " << x << endl; \
    RESET;

// 品红
#define DEBUG4(x)                     \
    MAGENTA;                          \
    cout << #x << " : " << x << endl; \
    RESET;

// 青色
#define DEBUG5(x)                     \
    CYAN;                             \
    cout << #x << " : " << x << endl; \
    RESET;

// 黄色
#define DEBUG6(x)                     \
    YELLOW;                           \
    cout << #x << " : " << x << endl; \
    RESET;


using namespace std;


const int N = 1e6 + 10, M = N * 2, INF = 1e9, mod = 998244353;

int n, m, k;
int a,b;
int ans = 0;
unordered_map<int,int> mp;
int P[N];

int h(int x,int y)
{
    return x * 1e10 + y;
}

int get(int x,int dlt)
{
    if (x == 1)
    {
        return 0;
    }
    else if (dlt == 1)
    {
        return x - 1;
    }
    if (mp.find(h(x,dlt + x)) != mp.end()) return mp[h(x,dlt + x)];
    mp[h(x,dlt + x)] = x - 1;
    FOR(j,1,n)
    {
        int i = P[j];
        if (dlt % i == 0)
        {
            int res = x % i;
            mp[h(x,dlt + x)] = min({mp[h(x,dlt + x)],get(x / i,dlt / i) + res + 1,get(x / i + 1,dlt / i + 1) + i - res + 1});
        }
    }
    return mp[h(x,dlt + x)];
}

void solve()
{
    cin >> a >> b;
    if (a > b) swap(a,b);
    int dlt = b - a;

    n = 0;
    int res = dlt;
    FOR(i,2,res / i)
    {
        if (res % i == 0)
        {
            P[++n] = i;
            while (res % i == 0)
            {
                res /= i;
            }
        }
    }
    if (res != 1) P[++n] = res;
//    ans = min(ans,get(a,dlt));
    cout << get(a,dlt) << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    auto t = clock();
    int T = 1;
    cin >> T;
    while (T--)
    {
        solve();
    }
    auto tt = clock();

//    cout << "Time: " << 1000.0 * (tt - t) / CLOCKS_PER_SEC << "ms" << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1063ms
memory: 104968kb

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:

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

result:

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