-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10258_ad_hoc.cpp
37 lines (37 loc) · 1015 Bytes
/
10258_ad_hoc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// 220820 #10258 Switch Array Gold I
// math, ad_hoc
#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define int long long
#define all(v) (v).begin(), (v).end()
#define press(v) (v).erase(unique(all(v)), (v).end())
using namespace std;
typedef pair<int, int> pi;
typedef pair<int,pi> pii;
const int MAX = 30+7;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int N,t;
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin>>t;
while(t--){
string s;
cin>>s;
int ans=0,vis[MAX],d[MAX];
for (int i = 0; i < sz(s); i++) {
vis[i]=0;d[i]=0;
if(s[i]=='1')d[i]=1;
}
for (int i = 0; i < sz(s); i++) {
if(d[i]!=vis[i]){
// toggle -> up from right side -> operation rule 2 -> 1<<(i-1)
ans+=pow(2,sz(s)-i-1);
// toggle now and now+1
vis[i]=(vis[i]+1)%2;
vis[i+1]=(vis[i+1]+1)%2;
}
}
cout<<ans<<"\n";
}
}