Skip to content

Commit 48fc032

Browse files
committed
returning to training
1 parent ffb7a15 commit 48fc032

File tree

21 files changed

+2036
-0
lines changed

21 files changed

+2036
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
37+
void solve() {
38+
39+
cin >> N >> M;
40+
41+
K = pow(N, M) + pow(M, N);
42+
43+
cout << K << endl;
44+
}
45+
46+
int main() {
47+
48+
//optimize;
49+
50+
T = 1;
51+
52+
//cin >> T;
53+
54+
while(T--) {
55+
solve();
56+
}
57+
58+
return 0;
59+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
38+
bool f(int l, int r) {
39+
40+
string str(s.begin() + l, s.begin() + r + 1);
41+
42+
int n = str.size();
43+
44+
for(int i = 0; i < n / 2; i++) {
45+
if(str[i] != str[n - 1 - i]) return false;
46+
}
47+
48+
return true;
49+
}
50+
51+
void solve() {
52+
53+
cin >> s;
54+
55+
N = s.size();
56+
57+
int ans = 1;
58+
59+
for(int i = 0; i < N; i++) {
60+
for(int j = i; j < N; j++) {
61+
if(f(i, j)) {
62+
ans = max(ans, j - i + 1);
63+
}
64+
}
65+
}
66+
67+
cout << ans << endl;
68+
69+
}
70+
71+
int main() {
72+
73+
//optimize;
74+
75+
T = 1;
76+
77+
//cin >> T;
78+
79+
while(T--) {
80+
solve();
81+
}
82+
83+
return 0;
84+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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+
37+
void solve() {
38+
39+
cin >> N;
40+
41+
string s[3];
42+
map<char, vector<int>> m[3];
43+
44+
for(int i = 0; i < 3; i++) cin >> s[i];
45+
46+
for(int i = 0 ; i < 3; i++) {
47+
for(int j = 0; j < N * 3; j++) {
48+
m[i][ s[i][j%N] ].push_back(j);
49+
}
50+
}
51+
52+
int ans = INF;
53+
54+
for(auto [k, a]: m[0]) {
55+
56+
auto b = m[1][k];
57+
auto c = m[2][k];
58+
59+
// cerr << k << ": " << a << " " << b << " " << c << endl;
60+
61+
for(int t1: a) {
62+
for(int t2: b) {
63+
for(int t3: c) {
64+
if(t1 != t2 && t1 != t3 && t2 != t3) {
65+
int curr = max(t1, t2);
66+
curr = max(curr, t3);
67+
68+
ans = min(ans, curr);
69+
}
70+
}
71+
}
72+
}
73+
}
74+
75+
if(ans == INF) ans = -1;
76+
77+
cout << ans << endl;
78+
}
79+
80+
int main() {
81+
82+
optimize;
83+
84+
T = 1;
85+
86+
//cin >> T;
87+
88+
while(T--) {
89+
solve();
90+
}
91+
92+
return 0;
93+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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<ll,ll> 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+
bool vis[MAXN];
37+
pii ans[MAXN];
38+
vector<pii> adj[MAXN];
39+
pii edge[2 * MAXN];
40+
41+
void bfs(ll s) {
42+
43+
queue<ll> q;
44+
45+
q.push(s);
46+
47+
while(q.size()) {
48+
ll u = q.front();
49+
q.pop();
50+
51+
for(ll i = 0; i < adj[u].size(); i++) {
52+
ll v = adj[u][i].first;
53+
ll e = adj[u][i].second;
54+
55+
if(!vis[v]) {
56+
ans[v].first = ans[u].first + edge[e].first;
57+
ans[v].second = ans[u].second + edge[e].second;
58+
59+
vis[v] = true;
60+
61+
q.push(v);
62+
}
63+
}
64+
}
65+
}
66+
67+
void solve() {
68+
69+
cin >> N >> M;
70+
71+
for(int i = 0; i < M; i++) {
72+
73+
ll u, v, x, y;
74+
75+
cin >> u >> v >> x >> y;
76+
77+
u--, v--;
78+
79+
adj[u].push_back({v, i});
80+
adj[v].push_back({u, i + M});
81+
82+
edge[i] = make_pair(x, y);
83+
edge[i + M] = make_pair(-x, -y);
84+
}
85+
86+
bfs(0);
87+
88+
vis[0] = true;
89+
ans[0] = make_pair(0, 0);
90+
91+
for(int i = 0; i < N; i++) {
92+
if(vis[i]) cout << ans[i].first << " " << ans[i].second << endl;
93+
else cout << "undecidable" << endl;
94+
}
95+
96+
}
97+
98+
int main() {
99+
100+
optimize;
101+
102+
T = 1;
103+
104+
//cin >> T;
105+
106+
while(T--) {
107+
solve();
108+
}
109+
110+
return 0;
111+
}

0 commit comments

Comments
 (0)