Common BoardCould anyone help me with 17th test? AC now. I forgot the following: when building flow graph we need to set capacity equal to 1 when edge is mage->time and capacity equal to 0 when edge is time->mage. Edited by author 29.12.2011 02:09 Edited by author 29.12.2011 02:09 If use Dinis -> remember that Oriented Graph I really like geometric problems. The problem can be solved using LP, PCA, analysis. But how to apply computational geometry (convex hull) to the problem? The optimal line goes through two points; it's not some arbitrary line. This could lead to O(N^3) solution if you enumerate every of N(N-1)/2 lines and compute the distance in O(N). A better solution is doing two-pointers optimization for every point. For each point you have to sort all the other points according to their polar angle with the fixed point; and then computation of O(N) lines for a fixed endpoint takes linear time with two pointers. Complexity of this solution is O(N^2 log N). Just recall that point-line distance is given by the formula abs(a*X+b*Y)/sqrt(a*a+b*b) (as one of endpoints is treated as an origin there is no constant term in abs()). So you could group points (X,Y) into two groups: those that have a positive sign of (a*X+b*Y) and those that have a negative one — this is precisely what you need two pointers for. Then the answer for each line will be computed as (a*sumX_PositiveGroup + b*sumY_PositiveGroup - a*sumX_NegativeGroup - b*sumY_NegativeGroup)/sqrt(a*a+b*b). Edited by author 26.05.2020 12:21 Is it 6 for all where n=1 and a,b>0? Because my AC solution gives 9 (yes, I implement idea from forum). For test 1 10 10 my solution gives 121 0 x y xx yy xy Edited by author 26.05.2020 00:20 Edited by author 26.05.2020 00:20 does anyone know what is this test? thanks You can shoot in dead player I can get the right answer of 50 500,but I can't AC the second test..What's up? What's the data? Maybe for test 2 3 answer 0 thanks very much for your advice Than you: for test 2 3 answer 0 > test 2 3 This test is not correct cause S must be even. Update: Sorry, S can be odd! And yes, this is the second test case. Edited by author 23.05.2020 10:20 Edited by author 23.05.2020 10:20 Edited by author 28.09.2007 16:34 Ну я вспомнил что число в десятичной системе счисления Делится на 9 (то есть на 10-1) Если сумма его цифр делится на 9 Я предположил что в любой k-ичной системе счисления верно Что если сумма цифр некоторого числа делится на k-1 то и это число делится на k-1 И это оказалось правдой для тех k Которые содержатся в тестах к этой задаче. Большое спасибо! Эта подсказка мне помогла. Доказательство вашего утверждения: Пусть мы сейчас в k-ой системе счисления и если прочитать наше число X слева направо, то получим цифры a_n, a_{n - 1}, ... , a_1, a_0 (при этом 0 <= a_i <= k - 1 для всех i). Тогда в десятичной системе счисления оно будет равно X = a_n * k ^ n + a_{n - 1} * k ^ {n - 1} + ... + a_1 * k + a_0. Так как k = 1 (mod (k - 1)), то X = a_n + a_{n - 1} + ... + a_1 + a_0 (mod (k - 1)). Значит, X делится на (k - 1) тогда и только тогда, когда его сумма цифр делится на (k - 1). #include <iostream> using namespace std; int v[4001],w[4001],q[4001]; int se_gaseste (int val , int inceput , int sfarsit,int v[4001]) { int mijloc=(inceput+sfarsit)/2; if (v[mijloc]==val) return 1; if (inceput >= sfarsit) return 0; if (val>v[mijloc]) se_gaseste(val,mijloc+1,sfarsit,v); else se_gaseste(val,inceput,mijloc-1,v); } int main() { int n,m,t,nr=0; cin>>n; for (int i=1;i<=n;i++) cin>>v[i]; cin>>m; for (int i=1;i<=m;i++) cin>>w[i]; cin>>t; for (int i=1;i<=t;i++) cin>>q[i]; for (int i=1;i<=n;i++) { if ( se_gaseste(v[i],1,m,w) && se_gaseste(v[i],1,t,q)) nr++; } cout<<nr; return 0; } i tested this algorithm on many exemples and all works how i can't pass the first test, please help , thx. A little explication : i take every number from first vector and i check if exist in last both vectors . i use binary search Edited by author 22.05.2020 16:12 5 5 5 1 10 1 1 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 3 Ans: 9 5 5 10 8 8 7 6 8 8 7 6 5 8 7 6 5 4 7 6 5 4 3 6 5 4 3 4 2 2 1 2 Ans: 1 5 5 10 8 8 7 6 8 8 7 6 5 8 7 6 5 4 7 6 5 4 3 6 5 4 3 7 2 2 1 2 Ans: 2 3 3 1 1 1 1 1 1 1 1 10 1 1 2 2 Ans: -1 5 5 1 10 25 30 35 50 1 24 30 35 1 10 23 30 35 10 50 22 30 35 1 39 21 30 39 1 1 1 5 Ans: 9 Прекрасно работает в IDE, а на сервере ошибка. Объясните в чем дело import java.util.LinkedList; import java.util.Scanner; import static java.util.Collections.sort; public class Bird { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int i = sc.nextInt(); sumGol(minKol(i), toConteiner(i)); } public static LinkedList<Integer> toConteiner(int i) { Scanner sc = new Scanner(System.in); String[] str = sc.nextLine().split(" "); LinkedList<Integer> in = new LinkedList<>(); for (int j = 0; j < str.length; j++) in.add(Integer.parseInt(str[j])); return in; } public static int minKol(int i) { if (i % 2 != 0) i = i / 2 + 1; else i = i / 2; return i; } public static void sumGol(int i, LinkedList<Integer> l) { sort(l); int sum = 0; for (int j = 0; j < i; j++) { sum = sum + minKol(l.get(j)); } System.out.print(sum); } } На этот вопрос есть где-нибудь ответ? У меня другой код, та же ошибка. ( I found my mistake. Helpfull test: 4 1 2 3 100 4 5 6 7 2 1 7 ans: 1 4 HINT:This problem can be solved O(n) with stack. Edited by author 31.08.2016 10:07 Try to use 'longint' instead of 'int64'. In some problems it helps if you have WA. Thank you so much for the test! #include<bits/stdc++.h> using namespace std; stack<char> S; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; int len = s.length(); for(int i = 0; i < len;i++) { char c; if(S.empty()) c = 0; else c = S.top(); if(c == s[i]) S.pop(); else S.push(c); } string ans = ""; len = S.size(); for(int i = 0; i < len;i++) { char c = S.top(); ans += c; S.pop(); } reverse(ans.begin(),ans.end()); cout << ans; } You should do S.push(s[i]) in your else clause inside the for loop. I used DSU and I have WA16. Can you help me? I can't help you without code. I have never WA#16. I only have several MLE's before AC. "/* const int maxn = 100100; int a[maxn], b[maxn], c[maxn]; bool order[maxn]; int cnt; int p[maxn], rank[maxn]; int find_set(int x) { if(p[x] == x) return x; return p[x] = find_set(p[x]); } int unite(int x, int y) { x = find_set(x); y = find_set(y); if(x == y) return 0; if(rank[x] > rank[y]) { p[y] = x; } else { p[x] = y; if(rank[x] == rank[y]) rank[y] ++; } return 1; } int main() {
int n, m, q; scanf("%d%d", &n, &m); for (int i = 0; i < m; i ++) { scanf("%d%d", a + i, b + i); } scanf("%d", &q); for (int i = 0; i < q; i ++) { scanf("%d", c + i); order[--c[i]] = true; } for (int i = 0; i < n; i ++) p[i] = i; cnt = n; for (int i = 0; i < n; i ++) { if(order[i] == false) { cnt -= unite(a[i], b[i]); } }
c[q] = cnt; for (int i = q - 1; i > 0; i --) { cnt -= unite(a[c[i]], b[c[i]]); c[i] = cnt; } for (int i = 1; i < q; i ++) printf("%d ", c[i]); printf("%d", c[q]); }*/" You have a cycle where you are calculating cnt for q. The limit is wrong. i<n is wrong. i<m is correct. Because of m is number of edges not n. I changed n to m in your code and got AC again. Thanks Mahilewets!!! Is your idea same or not ? Idea is the same. I was getting MLE because of critical mistake in find_set. There was an iterative implementation. My iterative function was equivalent to : return (par[x] == x) ? x : par[x] =find_set (x) ; Thanks for your answer ! cause i made the same problem! The good part is Initially I made such mistakes incredible often But after only few months of regular basis practice Such blunders almost completely disappeared i do exactly same mistake and get wa at test 16 thnx Mahilewets Nikita [BSUIR] If you fail there, maybe you have forgotten that there could be only one person in a party at some contest. Edited by author 18.10.2009 23:32 I think, you is wrong. By your logic - in second demo test answer may be Fominykh (team contains only Fominykh) It's not true. gvsmirnov meant that you can get on input team of 1 person Edited by author 19.05.2020 20:44 Edited by author 19.05.2020 20:44 what will the output if input = 1 or 0 and why? if n=0 then q=10 if n=1 then q=1 Should be 11 though, I don't know why authors decided on 1. The solution requires a product of digits. 1 by itself isn't a product at all. Edited by author 19.05.2020 18:51 I solved this problem as follows: each player will try to choose the side that has less chance to win against the other. In my examples, everything works, but when I submit for verification, test 6 fails =(. Please explain how to solve it, I'm a beginner, and very interested in solving this problem. How do you calculate the chances of winning on the chosen side? Maybe I'm an addict, but since n<=5e6<2^24 I used unsigned short + unsigned char in order to immitate 3 byte integer type. Any hint for WA3? 'm stuck with WA5 :( 'm stuck with WA5 :( Don't forget rotate clockwise and anticlockwise at one step! Yes, rotating just 90 degrees in either directions takes one step. What's the trick here? This test helped me to overcome WA3: 4 2 2 3 3 1 4 1 3 2 3 1 1 4 4 2 The answer is 4. Because collect '4' needs 5 steps, but collect '1' needs only 4 steps. My answer is 4. I made a classic backtracking which gets WA3 and also a Greedy who also gets WA3, which works as follows: - assume the square is solved with 1 in the upper left corner, compute the orientation of each of the layers (0 if ok, 1 or 3 if with a rotation we reach 1 in the corner, 2 if with 2 rotations). - now try to rotate the layers to achieve the color i in the upper left corner - so for each layer determine the minimal nr. of steps to move the color i from layer j in its correct position - compute the minimal number of moves to reach the solution with color i in upper-left - print the minimum out of those values Edited by author 25.10.2011 15:22 I figured out the test #3, it has T[0][0] = 2, T[0][1] = T[1][0] = 1, T[1][1] = 3, "if (...) while(1);" did the trick. So the whole table I assume is 2 1 2 4 1 3 1 2 3 4 2 4 1 3 4 3 My program outputs 2 as a minimum (rotate layer 4 clockwise with 90, rotate layer 3 anti-clockwise with 90), resulting a solved cube with 1 in its left corner. The judge answer is 3, but I don't understand why. Am I missing something? Edited by author 26.10.2011 00:04 AC at last! The problem in my solution was that I assumed always that the colors were 1-red, 2-yellow, 3-green, 4-blue, but they say that one number is one color so they could be permuted in any way. Edited by author 27.10.2011 01:55 My AC program gives 2 as the answer for: 2 1 2 4 1 3 1 2 3 4 2 4 1 3 4 3 My AC program gives 2 as the answer for: 2 1 2 4 1 3 1 2 3 4 2 4 1 3 4 3 Strange. Mine gives 3. (Also AC). Edited by author 29.06.2012 20:52My AC program gives 2 as the answer for: 2 1 2 4 1 3 1 2 3 4 2 4 1 3 4 3 Strange. Mine gives 3. (Also AC). Edited by author 29.06.2012 20:52It's obvious that the answer is 2. Bad tests :) Mine gives 2 and I got AC for this input: 2 1 2 4 1 3 1 2 3 4 2 4 1 3 4 3 Edited by author 02.07.2019 19:33 But this test incorrect, because always colours order 1-2-3-4 IN this tet 1-2-4-3. My AC solution also gives 3. This test helped me to overcome WA3: 4 2 2 3 3 1 4 1 3 2 3 1 1 4 4 2 The answer is 4. Because collect '4' needs 5 steps, but collect '1' needs only 4 steps. You're wrong. The answer is equal for every colour cause you cann't collect only one colour but all the colours together. To collect '4' you must turn left inner square and turn right two outer squares each for 1 time. So we have 3 steps in sum. P. S. Sorry for bad english ( Edited by author 29.08.2012 23:31 Edited by author 29.08.2012 23:31 Edited by author 29.08.2012 23:33If we turn squares as you said we will get this situation: 4 3 3 3 4 4 3 2 4 1 2 2 1 1 1 2 If we turn squares as you said we will get this situation: 4 3 3 3 4 4 3 2 4 1 2 2 1 1 1 2 Yes, you're right ))) We need one more step - turn right the square which includes element table[3][1]. So, the answer is 4. ac is reached just using 4 elements in inputs. This problem can be solved without random exirsices :) I have got AC just by writing triads in order(without spaces): aaa aab aac aad... aba abb abc abd... zzz. I did it recursivly. And then you must repeat this sequence until number of characters=10^6; I did the same and was actually surprised when it worked! I have got no idea why would people have problems with this one, it's really easy to solve Does anyone know what this could be related to? I found the following test when got WA4: INPUT: aaa OUTPUT: 4 |
|