dut新生大礼包3
A
https://atcoder.jp/contests/abc177/tasks/abc177_c?lang=en
#include <bits/stdc++.h> using namespace std; const int P = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; ++i) { cin >> a[i]; } long long ans = 0; long long sum = 0; for(int i = 0; i < n; ++i) { ans = (ans + sum * a[i]) % P; sum = (sum + a[i]) % P; } cout << ans << '\n'; return 0; }
B
https://atcoder.jp/contests/abc177/tasks/abc177_d?lang=en
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<vector<int> > G(n); for(int i = 0; i < m; ++i) { int a, b; cin >> a >> b; --a; --b; G[a].emplace_back(b); G[b].emplace_back(a); } vector<bool> vis(n); int ans = 0; for(int i = 0; i < n; ++i) { if(!vis[i]) { int cnt = 0; queue<int> q; q.emplace(i); vis[i] = true; while(!q.empty()) { int u = q.front(); q.pop(); cnt += 1; for(int v : G[u]) { if(!vis[v]) { vis[v] = true; q.emplace(v); } } } ans = max(ans, cnt); } } cout << ans << '\n'; return 0; }
C
https://atcoder.jp/contests/abc183/tasks/abc183_c?lang=en
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<vector<int> > t(n, vector<int> (n)); for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { cin >> t[i][j]; } } vector<int> id(n); iota(id.begin(), id.end(), 0); int ans = 0; do { int sum = 0; for(int i = 0; i < n; ++i) { sum += t[id[i]][id[(i + 1) % n]]; } if(sum == k) { ans += 1; } } while(next_permutation(id.begin(), id.end())); cout << ans / n << '\n'; return 0; }
D
https://atcoder.jp/contests/abc183/tasks/abc183_d?lang=en
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, w; cin >> n >> w; vector<int> s(n); vector<int> t(n); vector<int> p(n); for(int i = 0; i < n; ++i) { cin >> s[i] >> t[i] >> p[i]; } vector<long long> sum(200001); for(int i = 0; i < n; ++i) { sum[s[i]] += p[i]; sum[t[i]] -= p[i]; } for(int i = 0; i < 200000; ++i) { sum[i + 1] += sum[i]; } if(*max_element(sum.begin(), sum.end()) > w) { cout << "No" << '\n'; } else { cout << "Yes" << '\n'; } return 0; }
E
https://atcoder.jp/contests/abc182/tasks/abc182_c?lang=en
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<int> b; while(n) { b.emplace_back(n % 10); n /= 10; } int m = b.size(); int ans = m; for(int i = 0; i < 1 << m; ++i) { int sum = 0; for(int j = 0; j < m; ++j) { if(i >> j & 1) { sum += b[j]; } } if(sum % 3 == 0) { ans = min(ans, m - __builtin_popcount(i)); } } if(ans == m) { cout << -1 << '\n'; } else { cout << ans << '\n'; } return 0; }
F
https://atcoder.jp/contests/abc182/tasks/abc182_d?lang=en
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; ++i) { cin >> a[i]; } vector<long long> pre(n + 1); vector<long long> mx(n + 1); for(int i = 0; i < n; ++i) { pre[i + 1] = pre[i] + a[i]; mx[i + 1] = max(mx[i], pre[i + 1]); } long long cur = 0; long long ans = 0; for(int i = 1; i <= n; ++i) { ans = max(ans, cur + mx[i]); cur += pre[i]; } cout << ans << '\n'; return 0; }
G
https://atcoder.jp/contests/abc180/tasks/abc180_c?lang=en
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> ans; for(long long i = 1; i * i <= n; ++i) { if(n % i == 0) { ans.emplace_back(i); ans.emplace_back(n / i); } } sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); for(long long i : ans) { cout << i << '\n'; } return 0; }
H
https://atcoder.jp/contests/abc170/tasks/abc170_d?lang=en
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int m = 1000001; vector<int> a(n); vector<int> cnt(m); vector<bool> vis(m); for(int i = 0; i < n; ++i) { cin >> a[i]; cnt[a[i]] += 1; } for(int i = 1; i < m; ++i) { if(cnt[i] > 0) { for(int j = i + i; j < m; j += i) { vis[j] = true; } } } long long ans = n; for(int i : a) { if(cnt[i] > 1 || vis[i]) { ans -= 1; } } cout << ans << '\n'; return 0; }