# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
380940 |
2021-03-23T18:35:03 Z |
i_am_noob |
Lamps (JOI19_lamps) |
C++17 |
|
71 ms |
35692 KB |
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma")
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 826
#endif
inline char readchar(){
const int maxn=1000000;
static char buf[maxn],*p=buf,*q=buf;
if(p==q&&(q=(p=buf)+fread(buf,1,maxn,stdin))==buf) return EOF;
else return *p++;
}
inline int readint(){
int c=readchar(),x=0,neg=0;
while((c<'0'||c>'9')&&c!='-'&&c!=EOF) c=readchar();
if(c=='-') neg=1,c=readchar();
while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^'0'),c=readchar();
return neg?-x:x;
}
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
const int maxn=1000005;
//i_am_noob
int n,dp[2][maxn],pre0[maxn],pre1[maxn],minn0=inf,minn1=inf,minn2=inf,minn3=inf;
bool a[maxn],b[maxn];
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
#ifdef i_am_noob
freopen("input1.txt","r",stdin);
freopen("output1.txt","w",stdout);
freopen("output2.txt","w",stderr);
#endif
cin >> n;
a[0]=b[0]=0;
rep(n){
char c;
cin >> c;
a[i+1]=c=='1';
}
rep(n){
char c;
cin >> c;
b[i+1]=c=='1';
}
rep(n+1) a[i]^=b[i];
rep(n) bug(i+1,a[i+1]);
dp[0][0]=0,dp[1][0]=1;
pre0[0]=pre1[0]=0;
rep2(i,1,n+1){
pre0[i]=pre0[i-1],pre1[i]=pre1[i-1];
if(b[i]&&!b[i-1]) pre0[i]++;
if((b[i-1]||i==1)&&!b[i]) pre1[i]++;
bug(pre0[i],pre1[i]);
}
minn0=dp[b[1]][0]-pre0[1];
minn1=dp[b[1]^1][0]+(b[1]==1)-pre0[1];
minn2=dp[b[1]^1][0]-pre1[1];
minn3=dp[b[1]][0]+(b[1]==0)-pre1[1];
rep2(i,1,n+1){
dp[0][i]=dp[1][i]=inf;
bug(minn0,minn1,minn2,minn3);
dp[b[i]][i]=min(minn0,minn1)+pre0[i]+1;
dp[b[i]^1][i]=min(minn2,minn3)+pre1[i]+1;
dp[a[i]][i]=min(dp[a[i]][i],min(dp[a[i]][i-1],dp[a[i]^1][i-1]+(a[i]==1)));
minn0=min(minn0,dp[b[i+1]][i]-pre0[i+1]);
minn1=min(minn1,dp[b[i+1]^1][i]+(b[i+1]==1)-pre0[i+1]);
minn2=min(minn2,dp[b[i+1]^1][i]-pre1[i+1]);
minn3=min(minn3,dp[b[i+1]][i]+(b[i+1]==0)-pre1[i+1]);
bug(i,dp[0][i],dp[1][i]);
}
cout << min(dp[0][n],dp[1][n]) << "\n";
return 0;
}
Compilation message
lamp.cpp: In function 'int main()':
lamp.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
lamp.cpp:72:12: note: in expansion of macro 'bug'
72 | rep(n) bug(i+1,a[i+1]);
| ^~~
lamp.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
lamp.cpp:79:9: note: in expansion of macro 'bug'
79 | bug(pre0[i],pre1[i]);
| ^~~
lamp.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
lamp.cpp:88:9: note: in expansion of macro 'bug'
88 | bug(minn0,minn1,minn2,minn3);
| ^~~
lamp.cpp:28:18: warning: statement has no effect [-Wunused-value]
28 | #define bug(...) 826
| ^~~
lamp.cpp:96:9: note: in expansion of macro 'bug'
96 | bug(i,dp[0][i],dp[1][i]);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
368 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 |
384 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 |
508 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 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
368 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 |
384 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 |
508 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 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
1 ms |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
1 ms |
492 KB |
Output is correct |
43 |
Correct |
1 ms |
492 KB |
Output is correct |
44 |
Correct |
1 ms |
492 KB |
Output is correct |
45 |
Correct |
1 ms |
492 KB |
Output is correct |
46 |
Correct |
1 ms |
492 KB |
Output is correct |
47 |
Correct |
1 ms |
492 KB |
Output is correct |
48 |
Correct |
1 ms |
492 KB |
Output is correct |
49 |
Correct |
1 ms |
492 KB |
Output is correct |
50 |
Correct |
1 ms |
492 KB |
Output is correct |
51 |
Correct |
1 ms |
492 KB |
Output is correct |
52 |
Correct |
1 ms |
492 KB |
Output is correct |
53 |
Correct |
1 ms |
492 KB |
Output is correct |
54 |
Correct |
1 ms |
492 KB |
Output is correct |
55 |
Correct |
1 ms |
492 KB |
Output is correct |
56 |
Correct |
1 ms |
492 KB |
Output is correct |
57 |
Correct |
1 ms |
492 KB |
Output is correct |
58 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 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 |
68 ms |
35564 KB |
Output is correct |
8 |
Correct |
67 ms |
35564 KB |
Output is correct |
9 |
Correct |
67 ms |
35564 KB |
Output is correct |
10 |
Correct |
69 ms |
35564 KB |
Output is correct |
11 |
Correct |
66 ms |
35564 KB |
Output is correct |
12 |
Correct |
69 ms |
35564 KB |
Output is correct |
13 |
Correct |
68 ms |
35564 KB |
Output is correct |
14 |
Correct |
66 ms |
35692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
368 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 |
384 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 |
508 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 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
1 ms |
364 KB |
Output is correct |
28 |
Correct |
1 ms |
364 KB |
Output is correct |
29 |
Correct |
1 ms |
364 KB |
Output is correct |
30 |
Correct |
1 ms |
364 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
33 |
Correct |
1 ms |
364 KB |
Output is correct |
34 |
Correct |
1 ms |
492 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
1 ms |
492 KB |
Output is correct |
37 |
Correct |
1 ms |
492 KB |
Output is correct |
38 |
Correct |
1 ms |
492 KB |
Output is correct |
39 |
Correct |
1 ms |
492 KB |
Output is correct |
40 |
Correct |
1 ms |
492 KB |
Output is correct |
41 |
Correct |
1 ms |
492 KB |
Output is correct |
42 |
Correct |
1 ms |
492 KB |
Output is correct |
43 |
Correct |
1 ms |
492 KB |
Output is correct |
44 |
Correct |
1 ms |
492 KB |
Output is correct |
45 |
Correct |
1 ms |
492 KB |
Output is correct |
46 |
Correct |
1 ms |
492 KB |
Output is correct |
47 |
Correct |
1 ms |
492 KB |
Output is correct |
48 |
Correct |
1 ms |
492 KB |
Output is correct |
49 |
Correct |
1 ms |
492 KB |
Output is correct |
50 |
Correct |
1 ms |
492 KB |
Output is correct |
51 |
Correct |
1 ms |
492 KB |
Output is correct |
52 |
Correct |
1 ms |
492 KB |
Output is correct |
53 |
Correct |
1 ms |
492 KB |
Output is correct |
54 |
Correct |
1 ms |
492 KB |
Output is correct |
55 |
Correct |
1 ms |
492 KB |
Output is correct |
56 |
Correct |
1 ms |
492 KB |
Output is correct |
57 |
Correct |
1 ms |
492 KB |
Output is correct |
58 |
Correct |
1 ms |
492 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
364 KB |
Output is correct |
61 |
Correct |
1 ms |
364 KB |
Output is correct |
62 |
Correct |
1 ms |
364 KB |
Output is correct |
63 |
Correct |
1 ms |
364 KB |
Output is correct |
64 |
Correct |
1 ms |
364 KB |
Output is correct |
65 |
Correct |
68 ms |
35564 KB |
Output is correct |
66 |
Correct |
67 ms |
35564 KB |
Output is correct |
67 |
Correct |
67 ms |
35564 KB |
Output is correct |
68 |
Correct |
69 ms |
35564 KB |
Output is correct |
69 |
Correct |
66 ms |
35564 KB |
Output is correct |
70 |
Correct |
69 ms |
35564 KB |
Output is correct |
71 |
Correct |
68 ms |
35564 KB |
Output is correct |
72 |
Correct |
66 ms |
35692 KB |
Output is correct |
73 |
Correct |
68 ms |
35564 KB |
Output is correct |
74 |
Correct |
67 ms |
35564 KB |
Output is correct |
75 |
Correct |
66 ms |
35564 KB |
Output is correct |
76 |
Correct |
68 ms |
35564 KB |
Output is correct |
77 |
Correct |
66 ms |
35564 KB |
Output is correct |
78 |
Correct |
66 ms |
35564 KB |
Output is correct |
79 |
Correct |
66 ms |
35564 KB |
Output is correct |
80 |
Correct |
67 ms |
35564 KB |
Output is correct |
81 |
Correct |
66 ms |
35564 KB |
Output is correct |
82 |
Correct |
65 ms |
35564 KB |
Output is correct |
83 |
Correct |
65 ms |
35564 KB |
Output is correct |
84 |
Correct |
67 ms |
35564 KB |
Output is correct |
85 |
Correct |
71 ms |
35564 KB |
Output is correct |
86 |
Correct |
65 ms |
35596 KB |
Output is correct |
87 |
Correct |
66 ms |
35564 KB |
Output is correct |
88 |
Correct |
66 ms |
35564 KB |
Output is correct |
89 |
Correct |
69 ms |
35564 KB |
Output is correct |
90 |
Correct |
66 ms |
35580 KB |
Output is correct |
91 |
Correct |
66 ms |
35692 KB |
Output is correct |
92 |
Correct |
69 ms |
35564 KB |
Output is correct |
93 |
Correct |
70 ms |
35564 KB |
Output is correct |
94 |
Correct |
68 ms |
35564 KB |
Output is correct |
95 |
Correct |
69 ms |
35564 KB |
Output is correct |
96 |
Correct |
70 ms |
35564 KB |
Output is correct |
97 |
Correct |
69 ms |
35584 KB |
Output is correct |
98 |
Correct |
68 ms |
35564 KB |
Output is correct |
99 |
Correct |
69 ms |
35692 KB |
Output is correct |
100 |
Correct |
69 ms |
35564 KB |
Output is correct |
101 |
Correct |
69 ms |
35564 KB |
Output is correct |
102 |
Correct |
69 ms |
35564 KB |
Output is correct |