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;
}
Thank you codeforces for this Round, Good to see many Div-3, and the standard of questions was perfect for the level of div-3
In problem E, in the second case (where two sections have exactly one section between them), how is the the number of shots required to break these two sections coming as ceil(Ai + Ai+2)/2?
such as A,X,B,if A>B,we can shoot X for B times,then shoot A for ceil((A-B)/2) times,and vice versa.You can find the result IS ceil(Ai + Ai+2)/2.
I think problem F will be done with Fenwick tree,too.
For problem E: is there some binary search solution?
You'd still have to take care of the 3 cases. But you can use binary search to solve for them. I used binary search for one of the cases.
155757986
It's interesting how none of the first three problems required loop.
How could problem E hacked so much!
Can anyone tell why I'm getting runtime error: Exit code is 2147483647 for submission: 155822852 I tried a lot but not understanding what's wrong.
Failing testcase: Ticket 6533
Thanks, but why does it not run as required?
There something wrong at line 100
tree[node1].push_back(node2);
. But I'm not able to understand why this is happening.After the contest, I successfully hacked most people with this example
In problem D, why does the parity of n determine i
n is length of the array "a", so if length of array "a" is even, you start checking adjacent elements from index 0, else if it's odd you start checking adjacent elements from index 1. This is because if you observe, if length is odd, then after all the operation the first element of "a" will remain at first position at "c".
!Thanks I get it!!!
can you please tell me my mistake in problem D(157254578)
Failing testcase: Ticket 7204
If you prefer command line, checkout CF Doctor for more flexibility and faster feedback.
If you are/were getting a WA/RE verdict on problems from this contest, you can get the smallest possible counter example for your submission on cfstress.com. To do that, click on the relevant problem's link below, add your submission ID, and edit the table (or edit compressed parameters) to increase/decrease the constraints.
If you are not able to find a counter example even after changing the parameters, reply to this thread (only till the next 7 days), with links to your submission and ticket(s).
Problem D is kinda sus
Anyone overcame testcase 32 of Problem E after getting WA? Or, any equivalent short length testcase please?
Failing testcase: Ticket 6752