답안 #230170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230170 2020-05-08T20:32:55 Z DS007 Lamps (JOI19_lamps) C++14
4 / 100
68 ms 5384 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, n_;
string a, b, a_, b_;

int toggle(int p) {
    while (p != n_ && a_[p] != 2 && a_[p] != b_[p])
        p++;
    return p;
}

int find(int l, int r) {
    if (l == r)
        return 0;
    else
        return 1 + (r - l) / 2;
}

int solve(int lp) {
    while (lp != n_ && a_[lp] == b_[lp])
        lp++;
    if (lp == n_)
        return 0;
    if (lp == n_ - 1)
        return 1;

    int last = n_;
    for (int p = lp; p < n_; p++) {
        if (a_[p] == b_[p])
            return find(lp, p) + solve(p + 1);
        if (a_[p] == '2')
            last = n_;
        else if (last == n_)
            last = p;
        else if (b_[p] != b_[lp] && last < p - 1)
            return find(lp, last) + 1 + solve(toggle(last));
    }

    return last == lp ? 1 : find(lp, n_);
}

int solveTestCase(int test) {
    cin >> n >> a >> b;

    for (int i = 0; i < n; n_++) {
        set<char> s;
        int temp = i;

        while (temp != n && b[temp] == b[i])
            s.insert(a[temp++]);

        b_ += b[i];
        a_ += s.size() == 2 ? '2' : *s.begin();
        i = temp;
    }

    //cout << a_ << endl << b_ << endl;
    cout << solve(0);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int test = 1;
    // cin >> test;
    for (int i = 1; i <= test; i++)
        solveTestCase(i);
}

Compilation message

lamp.cpp: In function 'long long int solveTestCase(long long int)':
lamp.cpp:61:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Incorrect 4 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Incorrect 4 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 11 ms 2844 KB Output is correct
8 Correct 66 ms 5384 KB Output is correct
9 Correct 65 ms 5380 KB Output is correct
10 Correct 65 ms 5380 KB Output is correct
11 Correct 68 ms 5384 KB Output is correct
12 Correct 11 ms 2844 KB Output is correct
13 Correct 11 ms 2844 KB Output is correct
14 Correct 12 ms 2844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Incorrect 4 ms 384 KB Output isn't correct
14 Halted 0 ms 0 KB -