Last active
February 19, 2020 16:32
-
-
Save Chgtaxihe/d86643d5f6fb1634e359df0df973057e to your computer and use it in GitHub Desktop.
Codeforces 1279 #Codeforces
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
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0, _iter_max=n; i<_iter_max; i++) | |
#define print(s) std::cout << s << std::endl | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const int inf = 0x3f3f3f3f; | |
const int maxn = 300 + 100; | |
void solve() { | |
ll r, g, b; | |
cin >> r >> g >> b; | |
if(r < g) swap(r, g); | |
if(g < b) swap(g, b); | |
if(r < g) swap(r, g); | |
// r >= g >= b | |
if(r > g + b + 1){ | |
cout << "NO\n"; | |
}else{ | |
cout << "YES\n"; | |
} | |
} | |
signed main() { | |
Android; | |
int t; | |
cin >> t; | |
while(t--) | |
solve(); | |
} |
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
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0, _iter_max=n; i<_iter_max; i++) | |
#define print(s) std::cout << s << std::endl | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const int inf = 0x3f3f3f3f; | |
const int maxn = 1e5 + 100; | |
ll a[maxn], presum[maxn]; | |
void solve() { | |
ll n, s; | |
cin >> n >> s; | |
a[0] = presum[0] = 0; | |
int best = 0, skip = 0; | |
for(int i=1; i<=n; i++) cin >> a[i]; | |
for(int i=1; i<=n; i++) presum[i] = presum[i-1] + a[i]; | |
for(int i=0; i<=n; i++){ | |
int l = 0, r = n, mid, ans=0; | |
while(l <= r){ | |
mid = (l + r) >> 1; | |
if(presum[mid] <= s + a[i]){ | |
ans = max(ans, mid); | |
l = mid + 1; | |
}else{ | |
r = mid - 1; | |
} | |
} | |
if(i > mid) break; | |
if(best < ans) best = ans, skip = i; | |
} | |
cout << skip << '\n'; | |
} | |
signed main() { | |
Android; | |
int t; | |
cin >> t; | |
while(t--) | |
solve(); | |
} |
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
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0, _iter_max=n; i<_iter_max; i++) | |
#define print(s) std::cout << s << std::endl | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const int inf = 0x3f3f3f3f; | |
const int maxn = 1e5 + 100; | |
void solve() { | |
int n, m; | |
cin >> n >> m; | |
vector<int> a(n + 1), pos(n + 1), b(m + 1); | |
F(i, n) cin >> a[i], pos[a[i]] = i; | |
F(i, m) cin >> b[i]; | |
ll cost = m, rmost = 0; | |
F(i, m){ | |
int p = pos[b[i]]; | |
if(p > rmost){ | |
cost += 2 * (p - i); | |
rmost = p; | |
} | |
} | |
cout << cost << '\n'; | |
} | |
signed main() { | |
Android; | |
int t; | |
cin >> t; | |
while(t--) | |
solve(); | |
} |
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
#include <bits/stdc++.h> | |
#define ll long long | |
#define ull unsigned long long | |
#define Android ios::sync_with_stdio(false), cin.tie(NULL) | |
#define F(i, n) for(int i=0, _iter_max=n; i<_iter_max; i++) | |
#define print(s) std::cout << s << std::endl | |
#define pii pair<int, int> | |
using namespace std; | |
void redirect_input() { freopen("./input.txt", "r", stdin); } | |
void redirect_output() { freopen("./output.txt", "w", stdout); } | |
const int inf = 0x3f3f3f3f; | |
const int maxn = 1e6 + 1000; | |
const ll mod = 998244353; | |
ll inv(ll val){ | |
int t = mod - 2; | |
ll ret = 1; | |
while(t){ | |
if(t & 1) ret = ret * val % mod; | |
t >>= 1; | |
val = val * val % mod; | |
} | |
return ret; | |
} | |
int cnt[maxn] = {0}; | |
int gift[maxn] = {0}; | |
void solve() { | |
ll n, inv_n, k, v, mx_a = -1; | |
cin >> n; | |
inv_n = inv(n); | |
for(int i=0; i<n; i++){ | |
cin >> k; | |
ll prob = inv_n * inv(k) % mod; | |
for(int j=0; j<k; j++){ | |
cin >> v; | |
mx_a = max(mx_a, v); | |
gift[v] = (1ll * gift[v] + prob) % mod; | |
cnt[v]++; | |
} | |
} | |
for(int i=0; i<=mx_a; i++){ | |
cnt[i] = cnt[i] * inv_n % mod; | |
} | |
int ans = 0; | |
for(int i=0; i<=mx_a; i++){ | |
ans = (ans + (1ll * cnt[i] * gift[i]) % mod) % mod; | |
} | |
cout << ans << '\n'; | |
} | |
signed main() { | |
Android; | |
solve(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment