QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#799345#9831. Hanoi Towers ReloadedFDUdululuWA 1ms3696kbC++201.3kb2024-12-05 11:27:162024-12-05 11:27:16

Judging History

This is the latest submission verdict.

  • [2024-12-05 11:27:16]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3696kb
  • [2024-12-05 11:27:16]
  • Submitted

answer

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

const int N = 1e5 + 5;
const ll mod = 998244353;

int n;
int a[N], b[N];
int flag;
ll mul, ans;

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];

    flag = 0;
    for (int i = n; i >= 1; i--) {
        if (flag)
            a[i] = 4 - a[i];
        if (a[i] == 2)
            flag ^= 1;
    }
    flag = 0;
    for (int i = n; i >= 1; i--) {
        if (flag)
            b[i] = 4 - b[i];
        if (b[i] == 2)
            flag ^= 1;
    }

    mul = 1, ans = 0;
    flag = 0;
    for (int i = n; i >= 1; i--) {
        if (a[i] > b[i]) {
            flag = 1;
            break;
        } else {
            flag = -1;
            break;
        }
    }
    for (int i = 1; i <= n; i++) {
        ll res = (a[i] - b[i]) * flag + mod;
        ans = (ans + res * mul % mod) % mod;
        mul = mul * 3ll % mod;
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

/*

4
1
1
3
2
3 3
2 1
3
3 2 1
1 2 3
4
2 1 3 2
2 1 3 2

*/

详细

Test #1:

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

input:

4
1
1
3
2
3 3
2 1
3
3 2 1
1 2 3
4
2 1 3 2
2 1 3 2

output:

2
7
20
0

result:

ok 4 number(s): "2 7 20 0"

Test #2:

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

input:

1000
1
1
1
2
3 1
2 2
2
1 3
3 2
1
1
3
2
1 3
2 2
2
2 1
1 1
2
2 1
3 3
1
3
2
2
1 3
3 3
2
2 3
1 2
2
1 2
3 1
2
3 2
3 1
2
2 3
1 2
2
3 3
3 1
2
3 3
2 2
1
3
1
2
3 2
2 1
1
3
3
2
2 2
3 1
1
1
2
1
1
1
2
3 2
2 2
1
1
1
1
3
2
1
1
1
1
3
1
2
2 3
2 2
1
3
3
2
3 3
1 3
2
3 3
2 1
2
3 3
1 2
1
3
2
1
3
3
2
1 3
2 1
2
1 1
1 1
1...

output:

0
2
3
2
2
998244352
7
1
2
2
3
1
2
6
4
2
2
0
2
1
0
1
0
1
0
2
3
0
998244351
7
3
1
0
5
0
0
2
7
3
1
1
5
0
998244352
2
0
2
2
0
1
1
0
1
998244351
1
8
2
1
1
1
1
1
2
1
4
1
2
0
0
1
0
5
2
2
2
2
2
1
1
2
0
1
1
2
3
1
998244352
0
0
6
2
1
1
4
3
1
1
6
2
2
998244351
2
5
3
0
0
0
5
2
0
0
3
0
3
0
2
1
0
998244352
0
1
0
...

result:

wrong answer 6th numbers differ - expected: '1', found: '998244352'