QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#60125 | #1900. Octopus Game | Sa3tElSefr# | WA | 3ms | 3652kb | C++23 | 2.0kb | 2022-11-02 23:42:01 | 2022-11-02 23:42:02 |
Judging History
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