Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int i = 0; i < t; i++)
{
int n;
cin >> n;
string s;
cin >> s;
cout << s.find("RL") + 2 << endl;
}
return 0;
}
Idea: fcspartakm
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
int mx = 0;
int ans = 0;
for(int i = 0; i < n; i++)
{
if(a[i] >= mx) ans++;
mx = max(mx, a[i]);
}
cout << ans << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 0; i < t; i++)
solve();
return 0;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
long long getOne(long long a, long long m)
{
return m / a;
}
long long getTwo(long long a, long long b, long long m)
{
return m / lcm(a, b);
}
long long getThree(long long a, long long b, long long c, long long m)
{
return m / lcm(lcm(a, b), c);
}
long long get(long long a, long long b, long long c, long long m)
{
long long c1 = getOne(a, m);
long long c2 = getTwo(a, b, m) + getTwo(a, c, m);
long long c3 = getThree(a, b, c, m);
return (c1 - c2 + c3) * 6 + (c2 - 2 * c3) * 3 + c3 * 2;
}
void solve()
{
long long a, b, c, m;
cin >> a >> b >> c >> m;
cout << get(a, b, c, m) << " " << get(b, a, c, m) << " " << get(c, a, b, m) << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 0; i < t; i++)
solve();
return 0;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--){
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
forn(i, m){
int v, u;
cin >> v >> u;
--v, --u;
g[v].push_back(u);
g[u].push_back(v);
}
vector<int> clr(n, -1);
int ans = 0;
forn(i, n) if (clr[i] == -1){
queue<int> q;
q.push(i);
clr[i] = 0;
vector<int> cnt(2);
bool ok = true;
while (!q.empty()){
int v = q.front();
q.pop();
++cnt[clr[v]];
for (int u : g[v]){
if (clr[u] == clr[v])
ok = false;
else if (clr[u] == -1){
clr[u] = clr[v] ^ 1;
q.push(u);
}
}
}
if (ok) ans += max(cnt[0], cnt[1]);
}
cout << ans << '\n';
}
return 0;
}
2204E - Sum of Digits (and Again)
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
int f(int x)
{
int res = 0;
while(x != 0)
{
res += x % 10;
x /= 10;
}
return res;
}
void solve()
{
string s;
cin >> s;
int n = s.size();
if(n == 1)
{
cout << s << "\n";
return;
}
vector<int> cnt(10);
int sum_digits = 0;
for(auto x : s)
{
cnt[x - '0']++;
sum_digits += x - '0';
}
for(int x = 1; x <= n * 9; x++)
{
int nx = x;
string sx = to_string(nx);
while(nx > 9)
{
nx = f(nx);
sx += to_string(nx);
}
//cout << x << " " << sx << endl;
vector<int> need_cnt(10);
int sum_digits_x = 0;
for(auto y : sx)
{
need_cnt[y - '0']++;
sum_digits_x += y - '0';
}
bool can = true;
for(int i = 0; i <= 9; i++)
if(need_cnt[i] > cnt[i]) can = false;
if(sum_digits - sum_digits_x != x)
can = false;
if(can)
{
string res = "";
for(int i = 9; i >= 0; i--)
{
for(int j = 0; j < cnt[i] - need_cnt[i]; j++)
res.push_back(char('0' + i));
}
res += sx;
cout << res << endl;
return;
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for(int i = 0; i < t; i++)
solve();
return 0;
}
Idea: adedalic
Tutorial
Tutorial is loading...
Solution (adedalic)
#include<bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())
#define x first
#define y second
typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
return out << "(" << p.x << ", " << p.y << ")";
}
template<class A> ostream& operator <<(ostream& out, const vector<A> &v) {
fore(i, 0, sz(v)) {
if(i) out << " ";
out << v[i];
}
return out;
}
const int INF = int(1e9);
const li INF64 = li(1e18);
const ld EPS = 1e-9;
const int MOD = 998'244'353;
int add(int a, int b) {
a += b;
while (a >= MOD)
a -= MOD;
while (a < 0)
a += MOD;
return a;
}
int mul(int a, int b) {
return a * 1ll * b % MOD;
}
int binPow(int a, int k) {
int ans = 1;
while (k > 0) {
if (k & 1)
ans = mul(ans, a);
a = mul(a, a);
k >>= 1;
}
return ans;
}
int n, m;
vector<int> a, k;
inline bool read() {
if(!(cin >> n >> m))
return false;
a.resize(n);
fore (i, 0, n)
cin >> a[i];
k.resize(m);
fore (i, 0, m)
cin >> k[i];
return true;
}
inline void solve() {
vector<int> lf(n, -1), rg(n, n);
vector<int> st;
fore (i, 0, n) {
while (!st.empty() && a[st.back()] > a[i])
st.pop_back();
if (!st.empty())
lf[i] = st.back();
st.push_back(i);
}
st.clear();
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && a[st.back()] >= a[i])
st.pop_back();
if (!st.empty())
rg[i] = st.back();
st.push_back(i);
}
int commonSum = 0;
vector<int> la(m + 1), lk(m + 1), ra(m + 1), rk(m + 1);
//[l, r)
auto addSeg = [](vector<int> &pS, int l, int r, int val) {
pS[l] = add(pS[l], val);
pS[r] = add(pS[r], -val);
};
fore (i, 0, n) {
int cnt = mul(i - lf[i], rg[i] - i);
int rem = add(mul(i + 1, n - i), -cnt);
int ia = binPow(a[i], MOD - 2);
commonSum = add(commonSum, mul(rem, ia));
int p = lower_bound(k.begin(), k.end(), a[i]) - k.begin();
addSeg(la, 0, p, mul(cnt, ia));
addSeg(lk, 0, p, mul(cnt, ia));
addSeg(ra, p, m, cnt);
addSeg(rk, p, m, mul(cnt, add(2, -a[i])));
}
fore (i, 0, m) {
la[i + 1] = add(la[i + 1], la[i]);
lk[i + 1] = add(lk[i + 1], lk[i]);
ra[i + 1] = add(ra[i + 1], ra[i]);
rk[i + 1] = add(rk[i + 1], rk[i]);
}
fore (i, 0, m) {
int ans = commonSum;
ans = add(ans, mul(add(la[i], ra[i]), k[i]));
ans = add(ans, add(lk[i], rk[i]));
cout << ans << '\n';
}
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
int tt = clock();
#endif
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
if(read()) {
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
return 0;
}
Idea: Roms
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
const int K = 301;
using mat = vector<vector<int>>;
int n, m, mod, k;
int add(int x, int y) {
x += y;
if (x >= mod) x -= mod;
return x;
}
int mul(int x, int y) {
return x * 1LL * y % mod;
}
unsigned long long aux[K][K];
mat mul(mat a, mat b) {
mat b2(k, vector<int>(k));
forn(x, k) forn(y, k) b2[x][y] = b[y][x];
mat c(k, vector<int>(k));
forn(x, k) forn(y, k) {
aux[x][y] = 0;
forn(z, k) {
aux[x][y] += a[x][z] * 1ll * b2[y][z];
if((z & 15) == 15)
aux[x][y] %= mod;
}
c[x][y] = aux[x][y] % mod;
}
return c;
}
mat binpow(mat a, int b) {
mat c(k, vector<int>(k));
forn(i, k) c[i][i] = 1;
while (b) {
if (b & 1) c = mul(c, a);
a = mul(a, a);
b >>= 1;
}
return c;
}
int main() {
cin >> n >> m >> mod;
k = 2 * m + 1;
mat a(k, vector<int>(k));
a[k - 1][k - 1] = 1;
forn(i, m) forn(f, 2) {
for (int l = f ? 0 : i; l <= i; ++l) {
for (int r = i; r < m; ++r) {
a[i * 2 + f][k - 1] = add(a[i * 2 + f][k - 1], 1);
for (int j = l; j <= r; ++j) {
a[i * 2 + f][j * 2 + (j == l)] = add(a[i * 2 + f][j * 2 + (j == l)], 1);
}
}
}
}
auto res = binpow(a, n);
cout << res[1][k - 1] << endl;
}








