Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for i in range(t):
x, y = map(int, input().split())
if y % x != 0:
print(0, 0)
else:
print(1, y // x)
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include <bits/stdc++.h>
using namespace std;
int main()
{
string w = "aa";
map<string, int> idx;
int i = 1;
for(w[0] = 'a'; w[0] <= 'z'; w[0]++)
for(w[1] = 'a'; w[1] <= 'z'; w[1]++)
if(w[0] != w[1])
idx[w] = i++;
int t;
cin >> t;
for(int i = 0; i < t; i++)
{
string s;
cin >> s;
cout << idx[s] << endl;
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
for _ in range(int(input())):
s = input()
t = input()
if t == "a":
print(1)
elif t.count('a') != 0:
print(-1)
else:
print(2**len(s))
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (adedalic)
fun main() {
repeat(readLine()!!.toInt()) {
val n = readLine()!!.toInt()
val a = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
for (i in (n % 2) until n step 2) {
if (a[i] > a[i + 1])
a[i] = a[i + 1].also { a[i + 1] = a[i] }
}
var sorted = true
for (i in a.indices)
if (i > 0 && a[i - 1] > a[i])
sorted = false
println(if(sorted) "YES" else "NO")
}
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (fcspartakm)
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <string>
#include <cstring>
#include <cassert>
#include <iomanip>
#include <algorithm>
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#define forn(i, n) for(int i=0;i<n;++i)
#define fore(i, l, r) for(int i = int(l); i <= int(r); ++i)
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define x first
#define y1 ________y1
#define y second
#define ft first
#define sc second
#define pt pair<int, int>
template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
template<typename X> inline X sqr(const X& a) { return a * a; }
typedef long long li;
typedef long double ld;
using namespace std;
const int INF = 1000 * 1000 * 1000;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);
const int N = 200 * 1000 + 13;
int n;
int a[N];
inline void read() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
}
inline void solve() {
int ans = INF;
for (int i = 0; i < n - 1; i++) {
int cur = 0;
int x = a[i], y = a[i + 1];
if (x < y) {
swap(x, y);
}
int cnt = min(x - y, (x + 1) / 2);
cur += cnt;
x -= 2 * cnt;
y -= cnt;
if (x > 0 && y > 0) {
cur += (x + y + 2) / 3;
}
ans = min(ans, cur);
}
for (int i = 0; i < n - 2; i++) {
int cur = 0;
int x = a[i], y = a[i + 2];
if (x < y) {
swap(x, y);
}
int cnt = (x - y + 1) / 2;
cur += cnt;
cur += y;
ans = min(ans, cur);
}
sort(a, a + n);
ans = min(ans, (a[0] + 1) / 2 + (a[1] + 1) / 2);
cout << ans << endl;
}
int main () {
#ifdef fcspartakm
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif
srand(time(NULL));
cerr << setprecision(10) << fixed;
read();
solve();
//cerr << "TIME: " << clock() << endl;
}
Idea: vovuh
Tutorial
Tutorial is loading...
Solution (vovuh)
#include <bits/stdc++.h>
using namespace std;
static char buf[1010];
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
vector<string> tmp(n);
string s;
int sum = 0;
for (int i = 0; i < n; ++i) {
scanf("%s", buf);
tmp[i] = buf;
sum += count(tmp[i].begin(), tmp[i].end(), '*');
}
for (int j = 0; j < m; ++j) {
for (int i = 0; i < n; ++i) {
s += tmp[i][j];
}
}
int res = count(s.begin(), s.begin() + sum, '.');
int pos = sum;
for (int i = 0; i < q; ++i) {
int x, y;
scanf("%d %d", &x, &y);
--x, --y;
int p = y * n + x;
if (p < pos) {
if (s[p] == '.') {
--res;
} else {
++res;
}
}
s[p] = (s[p] == '.' ? '*' : '.');
if (s[p] == '*') {
if (s[pos] == '.') {
++res;
}
++pos;
} else {
if (s[pos - 1] == '.') {
--res;
}
--pos;
}
printf("%d\n", res);
}
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;
const int INF = 1e9;
vector<int> in, out;
vector<vector<int>> g;
vector<int> dp;
int calc(int v){
if (dp[v] != -1) return dp[v];
if (in[v] >= 2 && out[v] >= 2){
dp[v] = 1;
for (int u : g[v])
dp[v] = max(dp[v], calc(u) + 1);
}
else if (in[v] >= 2){
dp[v] = 1;
}
else{
dp[v] = -INF;
}
return dp[v];
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
g.resize(n);
in.resize(n);
out.resize(n);
forn(i, m){
int v, u;
scanf("%d%d", &v, &u);
--v, --u;
g[v].push_back(u);
++in[u];
++out[v];
}
int ans = 1;
dp.resize(n, -1);
forn(v, n) if (out[v] >= 2){
for (int u : g[v]){
ans = max(ans, calc(u) + 1);
}
}
printf("%d\n", ans);
return 0;
}