/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 4ms 532.0 KiB
#3 Accepted 4ms 532.0 KiB
#4 Accepted 91ms 1.77 MiB
#5 Accepted 96ms 1.766 MiB

Code

#include <bits/stdc++.h>
using namespace std;

const int MAX_N = (int)1e5;
const int MAX_C = (int)1e9;

int n;
string s;
int r[MAX_N];
int c[MAX_N];
int v[MAX_N + 1];

void read() {
    cin >> n;
    assert(1 <= n && n <= MAX_N);
    
    cin >> s;
    assert((int)s.size() == n);
    for (int i = 0; i < n; ++i) {
        assert(s[i] == '0' || s[i] == '1');
    }
    
    for (int i = 0; i < n; ++i) {
        cin >> r[i]; --r[i];
        assert(i <= r[i] && r[i] < n);
    }    
    
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        assert(1 <= c[i] && c[i] <= MAX_C);
    }
}

int main() {
   // freopen("in5.txt", "r", stdin);
    //freopen("out5.txt", "w", stdout);

    read();
    int state = 0;
    long long sol = 0;
    for (int i = 0; i < n; ++i) {
        state ^= v[i];
        if (state ^ (s[i] - '0')) {
            state ^= 1;
            sol += c[i];
            v[r[i] + 1] ^= 1;
        }
    }
    cout << sol << "\n";
}

Information

Submit By
Type
Submission
Problem
P1125 Lumina's Light-Out Challenge
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-29 10:54:03
Judged At
2024-10-29 10:54:03
Judged By
Score
100
Total Time
96ms
Peak Memory
1.77 MiB