답안 #376225

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
376225 2021-03-11T05:00:50 Z casperwang Lamps (JOI19_lamps) C++14
0 / 100
1000 ms 12536 KB
#include <bits/stdc++.h>
#define All(x) x.begin(), x.end()
#define pb push_back
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 1000000;
int n;
string a, b;
int cnt;
int pre[MAXN+1];
vector <int> arr;
int ans;

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	cin >> a >> b;
	for (int i = 0; i < n; i++) {
		pre[i] = (i ? pre[i-1] : 0) + (a[i] != b[i]);
		cnt++;
		if (i+1==n || b[i] != b[i+1]) {
			int k = pre[i] - ((i-cnt>=0)?pre[i-cnt]:0);
			if (!k)
				arr.pb(0); // +++
			else if (k == cnt)
				arr.pb(1); // ---
			else if (pre[i]-pre[i-k] == k)
				arr.pb(2); // ++-
			else if (pre[i-cnt+k]-((i-cnt>=0)?pre[i-cnt]:0) == k)
				arr.pb(3); // -++
			else
				arr.pb(4); // other
			cnt = 0;
		}
	}
	pary(All(arr));
	bool flag = false;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[i]) {
			if (arr[i] == 1 || arr[i] == 2) {
				if (!flag) {
					if (arr[i] == 2) arr[i] = 1;
					flag = true;
					ans++;
				}
			} else if (arr[i] == 3) {
				if (flag) {
					arr[i] = 1;
					flag = false;
				}
			}
		} else {
			if (flag) {
				flag = false;
			}
		}
	}
	for (int i : arr) if (i > 1) ans++;
	cout << ans << '\n';
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |  for (int i = 0; i < arr.size(); i++) {
      |                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Incorrect 1 ms 364 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Incorrect 1 ms 364 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 11 ms 7612 KB Output is correct
8 Execution timed out 1074 ms 12536 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Incorrect 1 ms 364 KB Output isn't correct
17 Halted 0 ms 0 KB -