-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46296a9
commit 613e087
Showing
7 changed files
with
257 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include<iostream> | ||
#include <stdlib.h> | ||
#include <vector> | ||
using namespace std; | ||
#define int long long | ||
#define rep(i, a, b) for (int i = a; i < b; i++) | ||
|
||
|
||
void solve() { | ||
int n;string s;cin>>n>>s; | ||
int ans = 0; | ||
vector<bool>a(n+1,false),b(n+1,false); | ||
b[n-1] = (s[n-1]=='B'); | ||
a[0] = (s[0]=='A'); | ||
for(int i = n-2;i>=0;i--){ | ||
b[i] = (s[i]=='B') || (b[i+1]); | ||
} | ||
rep(i,1,n){ | ||
a[i] = (s[i] == 'A') || (a[i-1]); | ||
} | ||
rep(i,0,n-1){ | ||
ans += a[i] && b[i+1]; | ||
} | ||
cout<<ans<<'\n'; | ||
} | ||
|
||
|
||
int32_t main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
solve(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <algorithm> | ||
#include <bitset> | ||
#include <deque> | ||
#include <iostream> | ||
using namespace std; | ||
#define int long long | ||
// ------------------------------------------***-------------------------------------------------- | ||
|
||
int pow(int i){ | ||
if(i==0)return 1; | ||
return 10*pow(i-1); | ||
} | ||
|
||
vector<int>a; | ||
int32_t main() { | ||
int curr = 1; | ||
int digit = 1; | ||
while(digit<=18){ | ||
a.push_back(curr); | ||
curr+=9*digit*pow(digit-1); | ||
digit++; | ||
} | ||
int q,qq;cin>>q; | ||
while(q--){ | ||
cin>>qq; | ||
int i = 0; | ||
for(i = 0;i<18;i++){ | ||
if(a[i]>qq)break; | ||
} | ||
digit = i; | ||
int base = pow(digit-1); | ||
int offset = qq - a[digit-1]; | ||
base+=(offset)/digit; | ||
offset%=digit; | ||
// cout<<base<<' '<<digit<<' '<<offset<<'\n'; | ||
string num = to_string(base); | ||
cout<<num[offset]<<'\n'; | ||
// if(offset==0)cout<<num[len(num)-1]<<'\n'; | ||
// else cout<<num[offset-1]<<'\n'; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <bits/stdc++.h> | ||
#define endl '\n' | ||
|
||
typedef long long int ll; | ||
using namespace std; | ||
|
||
bool solve(int odd, int even, bool alice_winning, bool alice, vector<vector<vector<int>>>& memo) { | ||
if(odd == 0 && even == 0) { | ||
return alice_winning; | ||
} | ||
if(alice && memo[odd][even][alice_winning] != -1) | ||
return memo[odd][even][alice_winning]; | ||
if(alice) { | ||
bool option1 = false, option2 = false; | ||
if(odd > 0) option1 = solve(odd - 1, even, !alice_winning, false, memo); | ||
if(even > 0) option2 = solve(odd, even - 1, alice_winning, false, memo); | ||
return memo[odd][even][alice_winning] = max(option1, option2); | ||
} else { | ||
bool option1 = true, option2 = true; | ||
if(odd > 0) option1 = solve(odd - 1, even, alice_winning, true, memo); | ||
if(even > 0) option2 = solve(odd, even - 1, alice_winning, true, memo); | ||
return min(option1, option2); | ||
} | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
|
||
int t; | ||
cin >> t; | ||
while(t--) { | ||
int n, el; | ||
cin >> n; | ||
int odd = 0, even = 0; | ||
for(int i = 0; i < n; i++) { | ||
cin >> el; | ||
odd += (abs(el) % 2 == 1); | ||
even += (abs(el) % 2 == 0); | ||
} | ||
vector<vector<vector<int>>> memo(n+1, vector<vector<int>>(n+1, vector<int>(2, -1))); | ||
bool res = solve(odd, even, true, true, memo); | ||
cout << (res ? "Alice" : "Bob") << endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include<iostream> | ||
#include <stdlib.h> | ||
#include <vector> | ||
using namespace std; | ||
#define int long long | ||
#define rep(i, a, b) for (int i = a; i < b; i++) | ||
|
||
void solve() { | ||
int n;cin>>n; | ||
vector<int>a(n+1); | ||
rep(i,1,n+1)cin>>a[i]; | ||
vector<int>f(n+2,0); | ||
vector<int>m(n+2,0); | ||
if(a[n]==1)f[n]=1; | ||
for(int i = n-1 ; i>=1 ; i--){ | ||
f[i] = min( m[i+2] + a[i] + a[i+1],m[i+1] + a[i]); | ||
m[i] = min(f[i+1],f[i+2]); | ||
} | ||
cout<<f[1]<<'\n'; | ||
} | ||
int32_t main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
solve(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include<iostream> | ||
#include <stdlib.h> | ||
#include <vector> | ||
using namespace std; | ||
#define int long long | ||
#define rep(i, a, b) for (int i = a; i < b; i++) | ||
|
||
///DP solution | ||
void solve() { | ||
int n;string s;cin>>n>>s; | ||
int i = n-2; | ||
vector<int>ans(n+1,0); | ||
for(int i = n-2; i>=0;i--){ | ||
if(s.substr(i,3)=="map" || s.substr(i,3)=="pie"){ | ||
ans[i] = 1ll + min(ans[i+1],min(ans[i+2],ans[i+3])); | ||
} | ||
else ans[i] = ans[i+1]; | ||
} | ||
cout<<ans[0]<<'\n'; | ||
} | ||
|
||
/// greedy | ||
void solve(){ | ||
int n; | ||
cin >> n; | ||
string s; | ||
cin >> s; | ||
vector<int> va; | ||
for (string sul : {"mapie", "pie", "map"}) { | ||
for (int pos = 0; (pos = s.find(sul, pos)) != string::npos;) { | ||
s[pos + sul.length() / 2] = '?'; | ||
va.push_back(pos + sul.length() / 2); | ||
} | ||
} | ||
cout << va.size() << endl; | ||
} | ||
|
||
|
||
int32_t main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
solve(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include<iostream> | ||
#include <stdlib.h> | ||
#include <vector> | ||
using namespace std; | ||
#define int long long | ||
#define rep(i, a, b) for (int i = a; i < b; i++) | ||
|
||
|
||
void solve() { | ||
string s;cin>>s; | ||
int n = s.size(); | ||
vector<bool>a(n,true); | ||
int B=0,b=0; | ||
char c; | ||
for(int i = n-1; i>=0 ;i--){ | ||
c = s[i]; | ||
if(c=='b'){ | ||
a[i]=false; | ||
b++; | ||
} | ||
else if(c=='B'){ | ||
a[i]=false; | ||
B++; | ||
} | ||
else{ | ||
if('a'<=c && c<='z' && b>0){ | ||
a[i]=false; | ||
b--; | ||
} | ||
else if('A'<=c && c<='Z' && B>0){ | ||
a[i]=false; | ||
B--; | ||
} | ||
} | ||
} | ||
rep(i,0,n){ | ||
if(a[i])cout<<s[i]; | ||
} | ||
cout<<'\n'; | ||
} | ||
|
||
int32_t main() { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int t; | ||
cin >> t; | ||
while (t--) { | ||
solve(); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters