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
I think problem F will be done with Fenwick tree,too.
For problem E: is there some binary search solution?
It's interesting how none of the first three problems required loop.
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
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).
Anyone overcame testcase 32 of Problem E after getting WA? Or, any equivalent short length testcase please?
Failing testcase: Ticket 6752
can i any one tell what is wrong in my code for question infinite replacement void solved(){ string s; cin>>s; string t; cin>>t; bool infinite=false; if(t=="a") { cout<<"1\n"; return;} for(int i=0;i<t.size();i++){ if(t[i]=='a') { infinite=true; break; } } if(infinite){ cout<<"-1\n";
} else{ int ans = 1; for(int i=1;i<=s.size();i++){ ans = (ans*2)%Mod; if(ans<0) ans = ans+Mod; } cout<<ans<<"\n"; }
} int main(){ int t; cin>>t; while(t--){ solved(); } return 0; }
You are taking mod, thats why its giving WA for the cases where answer is >= Mod. The problem does not ask to take mod.
I know I'm quite late, but I don't see my solution to G.There is maybe a simpler (not sure if its simpler) solution to G. 1. Remove all edges u,v such that (inDegree[u]==1 || outDegree[v]==1). 2. Now the answer is the longest possible path in this new graph. Proof is also quite simple. Here is my 171163896
Amazing solution! Easy to understand and prove!
Question F so simple... why rated 1800? It suits problem B or even A div2.
How solved
My solution for F using segment tree 214543084
My approach to problem F: We can convert the given matrix to a 1-d array while traversing the matrix for each column from 1st row to the last nth row and placing 1 for a '*' and 0 for '.'
Let the current number of 1's in our array be x. So now we have to find the number of empty positions in our 1-d array in the range [0 , x — 1] , as we have to place 1's at that positions from the rest of the array
This can be easily done either with a rangeSum segment tree link or an ordered set link
son you are a genius to convert into 1d array. good work
O(q(n+m)) solution easily passes in problem F, making it easier than a 1400 in my opinion.
My submission: 285215206