| Show all threads Hide all threads Show all messages Hide all messages |
| What's wrong with my Test 2? | Garin | 1036. Lucky Tickets | 23 May 2020 10:15 | 6 |
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 |
| Чёрт знает почему это так | Mahilewets | 1104. Don’t Ask Woman about Her Age | 22 May 2020 21:26 | 3 |
Ну я вспомнил что число в десятичной системе счисления Делится на 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). |
| Wrong on test 1 ???????? | DanGeros | 1880. Psych Up's Eigenvalues | 22 May 2020 16:09 | 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 |
| Useful tests | Levon Oganesyan | 2113. Survive the flood | 21 May 2020 22:18 | 1 |
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 |
| Runtime error java | Schwarz | 1025. Democracy in Danger | 21 May 2020 02:02 | 2 |
Прекрасно работает в 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); } } На этот вопрос есть где-нибудь ответ? У меня другой код, та же ошибка. ( |
| why wa10? | Felix_Mate | 1987. Nested Segments | 20 May 2020 23:29 | 4 |
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! |
| Code not producing any output? | Naman Sharma | 1654. Cipher Message | 20 May 2020 13:21 | 2 |
#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. |
| What about WA16 ? | Khujamurod | 1671. Anansi's Cobweb | 20 May 2020 00:58 | 9 |
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] |
| Test 13 | gvsmirnov | 1728. Curse on Team.GOV | 19 May 2020 20:23 | 3 |
Test 13 gvsmirnov 18 Oct 2009 23:22 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 Re: Test 13 Oleg Strekalovsky aka OSt [Vologda SPU] 22 Oct 2009 22:56 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 |
| if n = 0 or n = 1 ? | Tanim | 1014. Product of Digits | 19 May 2020 18:51 | 4 |
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 |
| How to solve? Problem with T6... | Artyom_Puchkov | 2104. Game with a Strip | 18 May 2020 17:10 | 2 |
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? |
| A way to reduce memory | Igor Parfenov | 2040. Palindromes and Super Abilities 2 | 18 May 2020 14:00 | 1 |
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. |
| WA3 | morbidel | 1878. Rubinchik's Cube | 17 May 2020 00:33 | 18 |
WA3 morbidel 22 Oct 2011 16:05 Re: WA3 Anil Kishore 22 Oct 2011 16:21 Re: WA3 Strekalovsky Oleg [Vologda SPU #1] 23 Oct 2011 23:43 '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? Re: WA3 MOPDOBOPOT (USU) 25 Oct 2011 13:49 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 Re: WA3 Lucian Ilea 7 Nov 2011 21:37 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 Re: WA3 Soucup Adrian 29 Jun 2012 20:52 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:52Re: WA3 Squire [Lviv NU] 29 Aug 2012 23:21 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: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. Re: WA3 Squire [Lviv NU] 29 Aug 2012 23:31 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:33Re: WA3 MOPDOBOPOT (USU) 30 Aug 2012 00:09 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 Re: WA3 Squire [Lviv NU] 30 Aug 2012 01:16 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. |
| Simple | Mehas | 1219. Symbolic Sequence | 16 May 2020 16:39 | 5 |
Simple Mehas 25 Jul 2004 01:31 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 |
| WA4 | reshke'` | 2060. Subpalindrome pairs | 15 May 2020 15:38 | 2 |
WA4 reshke'` 12 Mar 2018 20:58 Does anyone know what this could be related to? Re: WA4 Alikhan Zimanov 15 May 2020 15:38 I found the following test when got WA4: INPUT: aaa OUTPUT: 4 |
| time exceeded。。can you help me make it faster? | xinxin | 1131. Copying | 15 May 2020 04:21 | 3 |
#include<stdio.h> #include<math.h> int main() { int n,k,i=1,s=1,t=0,temp=0; scanf("%d %d",&n,&k);
while(i<k) { s=s+i; i=2*i; t++;
if(s>=n) break; } while(s<n) { s=s+k; t++; } printf("%d",t); return 0; } while(s<n) { s=s+k; t++; } Isn't here (n-s)/k iterations? #pragma optimize( "g", on ) |
| How to find minimum teams using SCC? | ajay jadhav | 1742. Team building | 14 May 2020 20:45 | 1 |
I got AC for maximum temas using Kosaraju. and for minimum I started with nodes with no incoming edge and searched until it hit previously found node (cycle) this is 1 team. For disconnected cycles, run dfs in similar fashion incrementing teams by 1. |
| Hint | Ishmeet Singh Saggu | 1742. Team building | 14 May 2020 19:47 | 2 |
Hint Ishmeet Singh Saggu 28 Apr 2020 22:51 This question requires knowledge of Strongly Connected Component. If you don't know read about it. Good Luck !!! for max = number of strongly connected components. for min = ? |
| Error on submission with default core Java | Jose_Silva | 2004. Scientists from Spilkovo | 14 May 2020 17:50 | 1 |
Hi, I have submitted one solution with: new String("0").repeat(n) => n is one number, and the system not know repeat method for Java 1.8, what's about that?! It's core Java. Thanks, Jose |
| If you have WA #6 | PrankMaN | 1998. The old Padawan | 14 May 2020 13:02 | 1 |
> They fall until the total weight of the fallen stones exceeds k kilograms So weight of fallen rocks should be at least k + 1 |