QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#691372#7877. Balanced ArrayxizhaoWA 0ms3592kbC++202.0kb2024-10-31 11:11:012024-10-31 11:11:01

Judging History

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

  • [2024-10-31 11:11:01]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3592kb
  • [2024-10-31 11:11:01]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
#define x first 
#define y second
constexpr i64 mod = 1000000000000001729;
constexpr i64 P = 1000000613;
void solve() { 
    int n;
    cin >> n;
    vector<int> a(n + 1);
    auto get = [&](string s) -> int {
        int base = 1;
        int res = 0;
        for (int i = s.size() - 1; i >= 0; i--) {
            int x = 0;
            if (s[i] >= '0' && s[i] <= '9') x = s[i] - '0';
            else if (s[i] >= 'a' && s[i] <= 'z') {
                x = 10 + s[i] - 'a';
            }
            else {
                x = 36 + s[i] - 'A';
            }
            res += x * base;
            base *= 62;
        }
        return res;
    };
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        int x = get(s);
        a[i] = x;
    }
    vector<i64> ha(n + 1), pw(n + 1);
    pw[0] = 1;
    for (int i = 1; i <= n; i++) {
        ha[i] = ((i128)ha[i - 1] * P % mod + a[i]) % mod;
        pw[i] = (i128)pw[i - 1] * P % mod;
    }

    auto query = [&](int l, int len) -> i64 {
        return ((i128)ha[l + len - 1] - (i128)ha[l - 1] * pw[len] % mod) % mod; 
    };

    vector<int> qy;
    for (int i = n; i >= 1; i--) qy.push_back(i);
    vector<bool> ans(n + 1);
    auto check = [&](int r, int k) -> bool {
        int len = r - 2 * k;
        if ((query(1, len) + query(1 + 2 * k, len)) % mod == (2 * query(k + 1, len) % mod)) {
            return true;
        }
        return false;
    };
    for (int k = 1; k <= n; k++) {
        while (!qy.empty() && qy.back() - 2 * k < 1) {
            qy.pop_back();
        }
        while (!qy.empty() && check(qy.back(), k)) {
            ans[qy.back()] = true;
            qy.pop_back();
        }
    }
    for (int i = 1; i <= n; i++) cout << ans[i];
    cout << '\n';
}
int main() { 
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
} 

详细

Test #1:

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

input:

3
1 2 3

output:

001

result:

ok single line: '001'

Test #2:

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

input:

9
1 2 3 2 5 4 3 8 5

output:

001010111

result:

ok single line: '001010111'

Test #3:

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

input:

9
1C 3f 4S 3h 88 6x 4W d1 8c

output:

001010111

result:

ok single line: '001010111'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3548kb

input:

49
71FjQ 71FzG 71FjR 71FjG 71FjS 71F3G 71FjT 71ENG 71FjU 71ExG 71FzG 71Fko 71FjW 71FOM 71FPm 71FzG 71FPO 71FP9 71FzG 71Fkc 71FzG 7AXBr 71FPH 8nKLh 71Fk2 71FzG 71FkK 4AGIE 71Fk9 6EfCL 71FPN 71FjJ 71FPb 7H3TC 71Gks 71FzG 71FPI 71FzG 6Oayg 71FPc 71FPw 71FPN 71Fkm 71FPK 71FPK 6Az4J 71FPI 71FzG 71Fke

output:

0000110011001000000000001000000000110000100000001

result:

wrong answer 1st lines differ - expected: '0000111111001000000000001000000000110000100000001', found: '0000110011001000000000001000000000110000100000001'