# Codeforces Round #669 (Div. 2)

### A. Ahahahahahahahaha

Code
// Author : heyuhhh
// Created Time : 2020/09/08 22:50:25
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
void run() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> b;

for (int i = 0; i < n; i++) {
int j = i + 1, k = i + 2;
if (j < n && a[i] == a[j]) {
++i;
b.emplace_back(a[i]);
b.emplace_back(a[i]);
} else if (j < n && k < n) {
i = k;
b.emplace_back(a[i]);
b.emplace_back(a[i]);
} else if (j == n) {
if (a[i] == 0)
b.emplace_back(a[i]);
} else if (k == n) {
b.emplace_back(0);
break;
}
}

cout << sz(b) << '\n';
for (auto it : b)
cout << it << ' ';
cout << '\n';
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while(T--)
run();
return 0;
}


### B. B. Big Vova

Code
// Author : heyuhhh
// Created Time : 2020/09/08 22:39:15
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
void run() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.rbegin(), a.rend());
vector<int> b(n);
vector<bool> chk(n);
int g = 0;
for (int i = 0; i < n; i++) {
int now = -1, p;
for (int j = 0; j < n; j++) if (!chk[j]) {
if (__gcd(g, a[j]) > now) {
now = __gcd(g, a[j]);
p = j;
}
}
chk[p] = true;
b[i] = a[p];
g = __gcd(g, a[p]);
}
for (int i = 0; i < n; i++)
cout << b[i] << " \n"[i == n - 1];
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
int T; cin >> T; while(T--)
run();
return 0;
}


### D. Discrete Centrifugal Jumps

• $$j=i+1$$;
• $$max(h_{i+1},\cdots,h_{j-1})<min(h_i,h_j)$$;
• $$min(h_{i+1},\cdots,h_{j-1})<max(h_i,h_j)$$.

Code
// Author : heyuhhh
// Created Time : 2020/09/09 00:21:00
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
void run() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
vector<int> sta(n);
int top = -1;
vector<int> big(n);
for (int i = 0; i < n; i++) {
while (top >= 0 && a[sta[top]] <= a[i])
big[sta[top--]] = i;
sta[++top] = i;
}
while (top >= 0)
big[sta[top--]] = -1;
vector<int> small(n);
for (int i = 0; i < n; i++) {
while (top >= 0 && a[sta[top]] >= a[i])
small[sta[top--]] = i;
sta[++top] = i;
}
while (top >= 0)
small[sta[top--]] = -1;

vector<int> lbig(n);
for (int i = n - 1; i >= 0; i--) {
while (top >= 0 && a[sta[top]] <= a[i])
lbig[sta[top--]] = i;
sta[++top] = i;
}
while (top >= 0)
lbig[sta[top--]] = -1;
vector<int> lsmall(n);
for (int i = n - 1; i >= 0; i--) {
while (top >= 0 && a[sta[top]] >= a[i])
lsmall[sta[top--]] = i;
sta[++top] = i;
}
while (top >= 0)
lsmall[sta[top--]] = -1;

vector<vector<int>> G(n);
for (int i = 0; i < n; i++) {
if (lsmall[i] != -1)
G[i].push_back(lsmall[i]);
if (lbig[i] != -1)
G[i].push_back(lbig[i]);
if (small[i] != -1)
G[small[i]].push_back(i);
if (big[i] != -1)
G[big[i]].push_back(i);
}
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 1; i < n; i++) {
for (auto j : G[i]) {
dp[i] = min(dp[i], dp[j] + 1);
}
}
int res = dp[n - 1];
cout << res << '\n';
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}


Code
// Author : heyuhhh
// Created Time : 2020/09/09 11:25:07
#include<bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
void run() {
int n, m;
cin >> n >> m;
vector<vector<pii>> G(n);
for (int i = 0; i < m; i++) {
int u, v, t;
cin >> u >> v >> t;
--u, --v;
G[v].emplace_back(u, t);
}
vector<int> col(n, -1), dis(n, INF);
vector<bool> vis(n);
queue<int> q;
dis[n - 1] = col[n - 1] = 0;
q.push(n - 1);
while (!q.empty()) {
int v = q.front(); q.pop();
vis[v] = true;
for (auto& it : G[v]) {
int u = it.fi, t = it.se;
if (vis[u]) continue;
if (col[u] == -1) {
col[u] = 1 - t;
} else {
if (col[u] == t && dis[u] > dis[v] + 1) {
dis[u] = dis[v] + 1;
q.push(u);
}
}
}
}
int ans = dis[0];
if (ans == INF) ans = -1;
cout << ans << '\n';
for (int i = 0; i < n; i++)
cout << max(0, col[i]);
cout << '\n';
}
int main() {
#ifdef Local
freopen("input.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
}

posted @ 2020-09-09 12:32  heyuhhh  阅读(362)  评论(0编辑  收藏  举报