QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#60125#1900. Octopus GameSa3tElSefr#WA 3ms3652kbC++232.0kb2022-11-02 23:42:012022-11-02 23:42:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-02 23:42:02]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3652kb
  • [2022-11-02 23:42:01]
  • 提交

answer

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <climits>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <climits>

//#pragma GCC optimize("O3")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#define ll long long
#define ld  long double
using namespace std;

const int N = 2e5 + 5, lg = 19, mod = 998244353;
const int OO = 1e9 + 5;

vector<pair<int, ll>>ans;

bool neg = false;

void solve(ll a, ll b, int step) {
    if (!b) {
        return;
    }
    ans.emplace_back(step + 1,  (neg ? 1 : -1) * a / b);
    solve(b, a % b, 1 - step);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a, b;
    cin >> a >> b;
    if (!a || !b) {
        return cout << 0 << '\n', 0;
    }
    bool swapped = false;
    if (b > a) {
        swap(a, b);
        swapped = true;
    }
    if (a < 0 && b < 0) {
        neg = true;
        a *= -1;
        b *= -1;
    } else if (b < 0) {
        ll k = ceil(-1.0l * b / a);
        b += k * a;
        ans.emplace_back(2 - swapped,  k);
    }
    solve(a, b, swapped);
    cout << ans.size() << '\n';
    for (auto &i : ans) {
        cout << i.first << ' ' << i.second << '\n';
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

-3 9

output:

3
1 1
2 -1
1 -2

result:

ok heap reached 0 count in less than 50 steps

Test #2:

score: 0
Accepted
time: 3ms
memory: 3492kb

input:

-27 57

output:

4
1 1
2 -1
1 -1
2 -9

result:

ok heap reached 0 count in less than 50 steps

Test #3:

score: 0
Accepted
time: 2ms
memory: 3596kb

input:

56 15

output:

5
1 -3
2 -1
1 -2
2 -1
1 -3

result:

ok heap reached 0 count in less than 50 steps

Test #4:

score: 0
Accepted
time: 2ms
memory: 3652kb

input:

6 -2

output:

3
2 1
1 -1
2 -2

result:

ok heap reached 0 count in less than 50 steps

Test #5:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

-84 57

output:

4
1 2
2 -1
1 -1
2 -9

result:

ok heap reached 0 count in less than 50 steps

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3648kb

input:

-648 -315

output:

4
2 0
1 2
2 17
1 2

result:

wrong answer A: -45360 or B: -22041 must be equal to 0