답안 #1097621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1097621 2024-10-07T16:54:41 Z ten_xd Lamps (JOI19_lamps) C++17
0 / 100
1000 ms 8368 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(a,b) for(int a = 0; a < (b); ++a)
#define all(t) t.begin(), t.end()
#define pb push_back

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

const int N = 1e6+54321, INF = 2e9+54321;
const ll INF_L = (ll)2e18+54321;

int n,wyn;
string A,B;
int dp[N];

void solve()
{
	cin >> n >> A >> B;

	wyn = 0;

	if(A[0] == B[0]) dp[0] = 0;
	else dp[0] = 1;

	for(int i = 1; i < n; ++i)
	{
		if(A[i] == B[i]) dp[i] = dp[i-1];
		else
		{
			dp[i] = dp[i-1] + 1;
			int idx = i;
			while(idx-1 >= 0 and A[idx-1] != B[idx-1]) --idx;
			if(idx == 0) dp[i] = min(dp[i],1);
			else dp[i] = min(dp[i],dp[idx-1]+1);

			int zer = 0, jed = 0;
			if(B[i] == '0') zer = 1;
			else jed = 1;

			for(int j = i; j >= 0; --j)
			{
				if(j != i and B[j] != B[j+1])
				{
					if(B[j] == '0') ++zer;
					else ++jed;
				}
				int po = 0;
				if(j-1 >= 0) po = dp[j-1];
				dp[i] = min(dp[i],po+min(zer,jed)+1);
			}
		}
	}

	cout << dp[n-1] << '\n';
}

int main()
{	
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int T = 1;
	//cin >> T;
	while(T--) solve();

	return 0;
}

Compilation message

lamp.cpp:10: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   10 | #pragma GCC optimization ("O3")
      | 
lamp.cpp:11: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
   11 | #pragma GCC optimization ("unroll-loops")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 11 ms 8368 KB Output is correct
8 Execution timed out 1044 ms 4520 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Halted 0 ms 0 KB -