Skip to content

Commit a7d18b4

Browse files
committed
more problems solved
1 parent 82e4807 commit a7d18b4

File tree

28 files changed

+2557
-29
lines changed

28 files changed

+2557
-29
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K,A,B;
36+
void solve(){
37+
38+
string ans;
39+
40+
A = 1LL, B = 1LL;
41+
42+
while(A != N || B != M){
43+
if(N <= M/2){
44+
ans.push_back('0');
45+
M = M/2;
46+
}
47+
else if(__builtin_popcount(N + 1) != 1){
48+
ans.push_back('1');
49+
50+
ll aux = 1;
51+
while(aux < N){
52+
aux *= 2;
53+
}
54+
N = aux - N;
55+
}
56+
else{
57+
ans.push_back('1');
58+
N = 1;
59+
}
60+
}
61+
62+
reverse(all(ans));
63+
64+
cout << ans << endl;
65+
}
66+
67+
int main(){
68+
69+
optimize;
70+
71+
cin >> N >> M;
72+
73+
M = (1LL << M);
74+
75+
solve();
76+
77+
return 0;
78+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 1010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
int pot[MAXN];
37+
bool dp[MAXN][MAXN];
38+
string s, ans;
39+
40+
bool solve(int i, int j){
41+
42+
if(i == N) return !j;
43+
44+
if(!dp[i][j]) {
45+
46+
if(s[i] == '?'){
47+
for(int k = 0;k<=9;k++){
48+
if(!i && !k) continue;
49+
50+
if(solve(i+1, (j + pot[N-i-1] * k) % K)){
51+
ans[i] = k + '0';
52+
return dp[i][j] = true;
53+
}
54+
55+
}
56+
}
57+
else{
58+
int k = s[i] - '0';
59+
60+
return solve(i+1, (j + pot[N-i-1] * k) % K);
61+
}
62+
63+
dp[i][j] = true;
64+
}
65+
66+
return false;
67+
68+
69+
}
70+
71+
void solve(){
72+
73+
pot[0] = 1 % K;
74+
for(int i=1;i<N;i++) pot[i] = (pot[i-1] * 10) % K;
75+
76+
ans = s;
77+
78+
if(solve(0,0)) cout << ans << endl;
79+
else cout << -1 << endl;
80+
}
81+
82+
int main(){
83+
84+
optimize;
85+
86+
cin >> N >> K;
87+
88+
cin >> s;
89+
90+
if(N == 1 && s[0] == '?'){
91+
cout << "0\n";
92+
return 0;
93+
}
94+
95+
if(N > 1 && s[0] == '0'){
96+
cout << "-1\n";
97+
return 0;
98+
}
99+
100+
solve();
101+
102+
return 0;
103+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
int A[MAXN];
37+
38+
void solve(){
39+
40+
ll sum = 0;
41+
42+
for(ll i=0;i<25;i++){
43+
ll on = 0, off = 0;
44+
45+
for(ll j=0;j<N;j++){
46+
if(A[j] & (1LL << i)) on++;
47+
else off++;
48+
}
49+
50+
sum += on*on*on * (1LL << i);
51+
sum += 3LL * off*off*on * (1LL << i);
52+
}
53+
54+
cout << sum << endl;
55+
}
56+
57+
int main(){
58+
59+
optimize;
60+
61+
cin >> N;
62+
63+
for(int i=0;i<N;i++) cin >> A[i];
64+
65+
solve();
66+
67+
return 0;
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"files.associations": {
3+
"chrono": "cpp",
4+
"iostream": "cpp"
5+
}
6+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
5+
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
6+
7+
typedef long long ll;
8+
typedef long double ld;
9+
typedef pair<int,int> pii;
10+
11+
#define optimize ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
12+
#define endl "\n"
13+
14+
#define fi first
15+
#define se second
16+
#define pb push_back
17+
18+
#define all(x) x.begin(),x.end()
19+
#define ms(x,a) memset(x,a,sizeof(x))
20+
21+
#define INF 0x3f3f3f3f
22+
#define INFLL 0x3f3f3f3f3f3f3f3f
23+
24+
#define mod 1000000007LL
25+
#define MAXN 200010
26+
27+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
28+
29+
//#define _DEBUG
30+
// #ifdef _DEBUG
31+
// #endif
32+
33+
/* -------------------------------- Solution starts below -------------------------------- */
34+
35+
ll T,N,M,K;
36+
string s;
37+
int vai[MAXN], vem[MAXN];
38+
39+
bool vogal(int i){
40+
if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u') return true;
41+
return false;
42+
}
43+
44+
void erro(){
45+
cout << 0 << endl;
46+
exit(0);
47+
}
48+
49+
void pre(){
50+
51+
vai[0] = vogal(0);
52+
vem[N-1] = vogal(N-1);
53+
54+
for(int i=1;i<N;i++) vai[i] = vai[i-1] + vogal(i);
55+
for(int i=N-2;i>=0;i--) vem[i] = vem[i+1] + vogal(i);
56+
}
57+
58+
bool f(int l, int r){
59+
return vai[r] == vai[l];
60+
}
61+
62+
bool f2(int l, int r){
63+
return vem[l] == vem[r];
64+
}
65+
66+
int solve(int l, int r, bool rev){
67+
68+
if(l == r) return 1;
69+
70+
if(rev){
71+
if(vogal(r) && vogal(l)) return solve(l, r-1, !rev);
72+
if(vogal(r) && !vogal(l)) return f2(l,r) + solve(l+1, r, rev);
73+
if(!vogal(r) && vogal(l)) erro();
74+
if(!vogal(r) && !vogal(l)) return solve(l+1, r, rev);
75+
}
76+
else{
77+
if(vogal(l) && vogal(r)) return solve(l+1, r, !rev);
78+
if(vogal(l) && !vogal(r)) return f(l,r) + solve(l, r-1, rev);
79+
if(!vogal(l) && vogal(r)) erro();
80+
if(!vogal(l) && !vogal(r)) return solve(l, r-1, rev);
81+
}
82+
}
83+
84+
void solve(){
85+
86+
N = s.size();
87+
88+
pre();
89+
90+
int ans = solve(0,N-1,false);
91+
92+
cout << ans << endl;
93+
}
94+
95+
int main(){
96+
97+
optimize;
98+
99+
cin >> s;
100+
101+
solve();
102+
103+
return 0;
104+
}

0 commit comments

Comments
 (0)