Skip to content

Instantly share code, notes, and snippets.

@Chgtaxihe
Last active January 29, 2020 06:44
Show Gist options
  • Save Chgtaxihe/086b10066ac0b4c1fa9c5f3a274d376b to your computer and use it in GitHub Desktop.
Save Chgtaxihe/086b10066ac0b4c1fa9c5f3a274d376b to your computer and use it in GitHub Desktop.
Codeforces 1265 #Codeforces
#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; i<n; i++)
using namespace std;
void redirect_input() { freopen("./input.txt", "r", stdin); }
void redirect_output() { freopen("./output.txt", "w", stdout); }
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5 + 100;
char buffer[maxn];
char * candidate = "abc";
void solve() {
cin >> buffer;
int len = strlen(buffer);
if(buffer[0]=='?'){
if(buffer[1]=='a') buffer[0] = 'b';
else buffer[0] = 'a';
}
for(int i=1; i<len; i++){
if(buffer[i] == buffer[i-1]){
cout << -1 << '\n';
return;
}
if(buffer[i] == '?'){
F(j, 3){
if(buffer[i-1] != candidate[j] && buffer[i+1] != candidate[j]){
buffer[i] = candidate[j];
break;
}
}
}
}
cout << buffer << '\n';
}
signed main() {
Android;
int n;
cin >> n;
while(n--) solve();
}
#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; i<n; i++)
using namespace std;
void redirect_input() { freopen("./input.txt", "r", stdin); }
void redirect_output() { freopen("./output.txt", "w", stdout); }
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e5 + 100;
int pos[maxn];
bool mark[maxn];
void solve() {
int n, val, l, r;
cin >> n;
F(i, n+1) mark[i] = false;
F(i, n){
cin >> val;
pos[val] = i + 1;
}
l = r = pos[1];
mark[1] = true;
for(int i=2; i<=n; i++){
l = min(l, pos[i]);
r = max(r, pos[i]);
if(r - l + 1 == i) mark[i] = true;
}
for(int i=1; i<=n; i++) cout << mark[i];
cout << '\n';
}
signed main() {
Android;
int n;
cin >> n;
while(n--) solve();
}
#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; i<n; i++)
using namespace std;
void redirect_input() { freopen("./input.txt", "r", stdin); }
void redirect_output() { freopen("./output.txt", "w", stdout); }
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 4e5 + 100;
int p[maxn], cnt[maxn];
void solve() {
int n, val, idx=-1;
cin >> n;
F(i, n){
cin >> val;
if(idx == -1 || p[idx] != val){
idx++;
p[idx] = val, cnt[idx] = 0;
}
cnt[idx]++;
}
int g=cnt[0], s=0, c=0, cursor;
for(cursor=1; cursor<=idx; cursor++){
if(s <= g) s += cnt[cursor];
else if(c <= g) c += cnt[cursor];
else break;
}
if(g + s + c > n / 2){
cout << "0 0 0\n";
return;
}
for(; cursor <= idx; cursor++){
if(g + s + c + cnt[cursor] <= n / 2) c += cnt[cursor];
else break;
}
cout << g << " " << s << " " << c << "\n";
}
signed main() {
Android;
int n;
cin >> n;
while(n--) solve();
}
#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; i<n; i++)
using namespace std;
void redirect_input() { freopen("./input.txt", "r", stdin); }
void redirect_output() { freopen("./output.txt", "w", stdout); }
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int maxn = 1e5 + 100;
int oricnt[5]={0}, cnt[5], sum=0;
int ans[maxn];
bool gen_answer(int head){
F(i, 5) cnt[i] = oricnt[i];
ans[0] = head;
cnt[head] --;
for(int i=1; i<sum; i++){
int prev = ans[i-1];
if(prev == 0){
if(cnt[1] <= 0) {return false; }
ans[i] = 1;
cnt[1]--;
}else{
if(cnt[prev-1] > 0){
ans[i] = prev-1;
cnt[prev-1] -= 1;
}else{
if(cnt[prev + 1] <= 0) return false;
ans[i] = prev + 1;
cnt[prev + 1]--;
}
}
}
return true;
}
void solve() {
F(i, 4) cin >> oricnt[i], sum+=oricnt[i];
int min_idx = 0;
F(i, 4) if(oricnt[i] != 0){
min_idx = i;
break;
}
if(gen_answer(min_idx) || (oricnt[min_idx+1]>0 && gen_answer(min_idx+1))){
cout << "YES\n";
F(i, sum) cout << ans[i] << " ";
cout << endl;
}else{
cout << "NO\n";
}
}
signed main() {
Android;
solve();
}
#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; i<n; i++)
using namespace std;
void redirect_input() { freopen("./input.txt", "r", stdin); }
void redirect_output() { freopen("./output.txt", "w", stdout); }
const int maxn = 2e5 + 100;
const ll mod = 998244353;
ll p[maxn], inv[120];
ll cost[maxn] = {0};
ll calc_inv(ll val){
ll t = mod - 2;
ll ans = 1;
while(t){
if(t & 1) ans = ans * val % mod;
t >>= 1;
val = val * val % mod;
}
return ans;
}
void solve() {
for(int i=1; i<=100; i++) inv[i] = calc_inv(i);
int n;
cin >> n;
for(int i=1; i<=n; i++) cin >> p[i];
for(int i=1; i<=n; i++){
cost[i] = (cost[i-1] + 1) * 100LL % mod * inv[p[i]] % mod;
}
cout << cost[n] << '\n';
}
signed main() {
Android;
solve();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment