Skip to content

Commit 48ce031

Browse files
committed
more problems solved
1 parent a7d18b4 commit 48ce031

File tree

12 files changed

+1526
-0
lines changed

12 files changed

+1526
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"files.associations": {
3+
"iosfwd": "cpp",
4+
"*.tcc": "cpp",
5+
"iostream": "cpp"
6+
}
7+
}
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+
unordered_map<ll, ll> dp;
38+
set<ll> nums;
39+
40+
// P = 1, S = 2, R = 3;
41+
42+
ll solve(ll i){
43+
44+
if(dp.find(i) != dp.end()){
45+
return dp[i];
46+
}
47+
48+
ll ans = 0;
49+
ll p = *nums.upper_bound(-i);
50+
51+
ans = solve(i + p);
52+
53+
if(ans == 1) ans = 2;
54+
else if(ans == 2) ans = 3;
55+
else if(ans == 3) ans = 1;
56+
57+
return dp[i] = ans;
58+
}
59+
60+
void pre(){
61+
ll aux = 3LL;
62+
63+
while(aux < (ll) 1e13){
64+
nums.insert(-aux);
65+
aux *= 3LL;
66+
}
67+
68+
dp[1] = 3;
69+
dp[2] = 1;
70+
dp[3] = 2;
71+
}
72+
73+
void solve(){
74+
75+
int aux = solve(N);
76+
77+
if(aux == 1) cout << "S\n";
78+
if(aux == 2) cout << "R\n";
79+
if(aux == 3) cout << "P\n";
80+
}
81+
82+
int main(){
83+
84+
optimize;
85+
86+
pre();
87+
88+
while(cin >> N && N){
89+
solve();
90+
}
91+
92+
return 0;
93+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
37+
ll dp[MAXN][MAXN], fat[2 * MAXN];
38+
39+
// CB: cb[i][j] -> Quantas possibilidades tenho com i bolinhas pretas em j espaços
40+
// Dp: dp[i][j] -> Quantas possibilidades tenho com uma grade de tamanho i sendo que j posições já foram coloridas
41+
42+
void preCalc(){
43+
fat[0] = 1;
44+
45+
for(int i=1; i < 2*MAXN ;i++) {
46+
fat[i] = i * fat[i-1];
47+
fat[i] %= mod;
48+
}
49+
}
50+
51+
ll fastExp(ll a, ll n){
52+
53+
ll ret = 1, b = a;
54+
55+
while(n){
56+
if(n & 1) ret = (ret * b) % mod;
57+
b = (b * b) % mod;
58+
n >>= 1;
59+
}
60+
61+
return ret;
62+
}
63+
64+
ll cb(int i ,int j){
65+
return (fat[i+j] * ( fastExp( ( (fat[i] * fat[j] ) % mod) + mod , mod - 2) ) ) % mod;
66+
}
67+
68+
ll solve(int i, int j){
69+
70+
if(i < 0) return 1LL;
71+
if(!i && !j) return 2LL;
72+
if(!i && j == 1) return 1LL;
73+
74+
if(~dp[i][j]) return dp[i][j];
75+
76+
ll ans = 0;
77+
78+
if(j){
79+
ans = 2LL * ( ( solve(i-1,1) * solve(0,1) ) % mod ) * cb(2 * i -1,1);
80+
ans += solve(i-1, 0);
81+
ans %= mod;
82+
}
83+
else{
84+
ans = 2LL * solve(i,1);
85+
ans %= mod;
86+
}
87+
88+
return dp[i][j] = ans;
89+
}
90+
91+
void solve(){
92+
93+
ll ans = 0;
94+
95+
for(int i=0;i<N;i++) {
96+
ans += ( ( (solve(i,1) * solve(N-i-2,0) * 2LL) % mod) * cb(2 * (i+1) - 1, 2 * (N-i-1)) ) % mod;
97+
ans %= mod;
98+
}
99+
100+
cout << ans << endl;
101+
}
102+
103+
int main(){
104+
105+
optimize;
106+
107+
preCalc();
108+
ms(dp, -1);
109+
110+
while(cin >> N && N){
111+
solve();
112+
}
113+
114+
return 0;
115+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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+
37+
ll dp[MAXN][MAXN];
38+
ll cb[2 * MAXN][2 * MAXN];
39+
40+
// CB: cb[i][j] -> Quantas possibilidades tenho com i bolinhas pretas em j espaços
41+
// Dp: dp[i][j] -> Quantas possibilidades tenho com uma grade de tamanho i sendo que j posições já foram coloridas
42+
43+
void preCalc(){
44+
45+
cb[0][0] = 0;
46+
47+
for(int i=1;i<2 * MAXN;i++) cb[i][0] = 0, cb[0][i] = 1;
48+
49+
vector<ll> sum(2 * MAXN);
50+
iota(all(sum), 0);
51+
52+
for(int i=1;i < 2 * MAXN;i++){
53+
vector<ll> aux;
54+
ll acum = 0;
55+
56+
for(int j=0;j < 2 * MAXN;j++){
57+
cb[i][j] = sum[j];
58+
59+
acum += cb[i][j];
60+
acum %= mod;
61+
aux.pb(acum);
62+
}
63+
64+
sum = aux;
65+
}
66+
}
67+
68+
ll solve(int i, int j){
69+
70+
if(i < 0) return 1LL;
71+
if(!i && !j) return 2LL;
72+
if(!i && j == 1) return 1LL;
73+
74+
if(~dp[i][j]) return dp[i][j];
75+
76+
ll ans = 0;
77+
78+
if(j){
79+
ans = 2LL * ( ( solve(i-1,1) * solve(0,1) ) % mod ) * cb[2 * i -1][2];
80+
ans += solve(i-1, 0);
81+
ans %= mod;
82+
}
83+
else{
84+
ans = 2LL * solve(i,1);
85+
ans %= mod;
86+
}
87+
88+
return dp[i][j] = ans;
89+
}
90+
91+
void solve(){
92+
93+
ll ans = 0;
94+
95+
for(int i=0;i<N;i++) {
96+
ans += ( ( (solve(i,1) * solve(N-i-2,0) * 2LL) % mod) * cb[ 2 * (i+1) - 1 ][ 2 * (N-i-1) + 1 ]) % mod;
97+
ans %= mod;
98+
}
99+
100+
cout << ans << endl;
101+
}
102+
103+
int main(){
104+
105+
optimize;
106+
107+
preCalc();
108+
ms(dp, -1);
109+
110+
while(cin >> N && N){
111+
solve();
112+
}
113+
114+
return 0;
115+
}

0 commit comments

Comments
 (0)