Submission #127193

# Submission time Handle Problem Language Result Execution time Memory
127193 2019-07-09T06:01:54 Z dndhk Lamps (JOI19_lamps) C++14
4 / 100
184 ms 35852 KB
#include <bits/stdc++.h>

#define pb push_back
#define all(v) ((v).begin(), (v).end())
#define sortv(v) sort(all(v))
#define sz(v) ((int)(v).size())
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define umax(a, b) (a)=max((a), (b))
#define umin(a, b) (a)=min((a), (b))
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define rep(i,n) FOR(i,1,n)
#define rep0(i,n) FOR(i,0,(int)(n)-1)
#define FI first
#define SE second
#define INF 1000000000
#define INFLL 1000000000000000000LL


using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAX_N = 1000000;

int N;
string A, B;
pii type[MAX_N+1];
int dp[MAX_N+10][2][3];

int main(){
	scanf("%d", &N);
	cin>>A;
	cin>>B;
	for(int i=0; i<N; i++){
		type[i+1] = {(A[i] - '0'), (B[i] - '0')};
	}
	for(int i=0; i<2; i++){
		for(int j=0; j<3; j++){
			dp[0][i][j] = INF;
		}
	}
	dp[0][0][0] = 0;
	for(int n=1; n<=N; n++){
		for(int i=0; i<2; i++){
			for(int j=0; j<3; j++){
				dp[n][i][j] = INF;
				for(int i2=0; i2<2; i2++){
					for(int j2=0; j2<2; j2++){
						int pl = 0;
						if(i==1 && i2==0)	pl++;
						if(j!=j2 && j!=0)	pl++;
						dp[n][i][j] = min(dp[n][i][j], dp[n-1][i2][j2] + pl);
					}
				}
				if(type[n].first==0){
					if(type[n].second==0){
						dp[n][0][2] = dp[n][1][0] = dp[n][1][1] = INF;
					}else{
						dp[n][0][0] = dp[n][0][1] = dp[n][1][2] = INF;
					}
				}else{
					if(type[n].second==0){
						dp[n][0][0] = dp[n][0][2] = dp[n][1][1] = INF;
					}else{
						dp[n][0][1] = dp[n][1][0] = dp[n][1][2] = INF;
					}
				}
			}
		}
	}
	int ans = INF;
	for(int i=0; i<2; i++){
		for(int j=0; j<3; j++){
			ans = min(ans, dp[N][i][j]);
		}
	}
	cout<<ans;
	return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Incorrect 2 ms 256 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Incorrect 2 ms 256 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 181 ms 35648 KB Output is correct
8 Correct 184 ms 35684 KB Output is correct
9 Correct 182 ms 35608 KB Output is correct
10 Correct 182 ms 35704 KB Output is correct
11 Correct 183 ms 35852 KB Output is correct
12 Correct 181 ms 35684 KB Output is correct
13 Correct 181 ms 35684 KB Output is correct
14 Correct 182 ms 35680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 380 KB Output is correct
14 Incorrect 2 ms 256 KB Output isn't correct
15 Halted 0 ms 0 KB -