| Show all threads Hide all threads Show all messages Hide all messages |
| Wrong Answer #2 | nushrat | 1086. Cryptography | 15 Nov 2016 12:48 | 2 |
I have been stuck on this test 2 for a while now. I gave up then came back, but still don't know what I need to change. Here is my solution, I used 'sieve of eratosthenes' to get out the primes. Please help me out. Should I change my input range for array. #include <iostream> #include <math.h> using namespace std; int main() { __int64 n; cin >> n; __int64 *input_list = new __int64[n]; //__int64 *primes = new __int64[15000]; long int primes[20000] = { 0 };
// input the numbers for (int i = 0; i < n; i++) { cin >> input_list[i]; } // Let A be an array of Boolean values, indexed by integers 2 to n, //initially all set to true. //for i = 2, 3, 4, ..., not exceeding √n: //if A[i] is true: //for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n : //A[j] := false
//Output: all i such that A[i] is true. long int a[20000] = { 0 };
for (long int i = 2; i <= 20000; i++) { if (a[i] == 0) { for (long int j = i * i, c=1; j < 20000; j +=i, c++) { a[j] = 1; } } //cout << a[i] << ends; } for (long int i = 2, p=0; i <= 20000; i++) { if (a[i] == 0) { //cout << i << ends; primes[p] = i; p++; } else { continue; } } for (int i = 0; i < n; i++) cout << primes[input_list[i] - 1] << endl; return 0; } Edited by author 15.11.2016 09:33 For a test 5 2260 2261 2262 2263 2264 your program gives 19991 19993 19997 0 0. I tried an "obvious" fix, changing all 20000's into 200000's, to fit for 1 15000 test, but got a stack overflow error. I don't want to look too deep into it, so i'd rather suggest going an easy way. Just make IsPrime(int value), which would determine if the number is prime or not, then for i=1..infinity, add i into your array if it's prime, and stop after adding 15000 numbers. After that it should be easy. |
| propose to rejudge | Serhiy Ivanov | 1548. Sakura and Statistics | 15 Nov 2016 07:23 | 3 |
I was bit confused to obtain accepted. I applied my solution to test straightforward approach and obtain TLE but i'm not. With next example i would defenitely obtain TLE: 50 50 00000000000000000000000001111111111111111111111111 00000000000000000000000011111111111111111111111111 00000000000000000000000111111111111111111111111111 00000000000000000000001111111111111111111111111111 00000000000000000000011111111111111111111111111111 00000000000000000000111111111111111111111111111111 00000000000000000001111111111111111111111111111111 00000000000000000011111111111111111111111111111111 00000000000000000111111111111111111111111111111111 00000000000000001111111111111111111111111111111111 00000000000000011111111111111111111111111111111111 00000000000000111111111111111111111111111111111111 00000000000001111111111111111111111111111111111111 00000000000011111111111111111111111111111111111111 00000000000111111111111111111111111111111111111111 00000000001111111111111111111111111111111111111111 00000000011111111111111111111111111111111111111111 00000000111111111111111111111111111111111111111111 00000001111111111111111111111111111111111111111111 00000011111111111111111111111111111111111111111111 00000111111111111111111111111111111111111111111111 00001111111111111111111111111111111111111111111111 00011111111111111111111111111111111111111111111111 00111111111111111111111111111111111111111111111111 01111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111111 11111111111111111111111111111111111111111111111110 11111111111111111111111111111111111111111111111100 11111111111111111111111111111111111111111111111000 11111111111111111111111111111111111111111111110000 11111111111111111111111111111111111111111111100000 11111111111111111111111111111111111111111111000000 11111111111111111111111111111111111111111110000000 11111111111111111111111111111111111111111100000000 11111111111111111111111111111111111111111000000000 11111111111111111111111111111111111111110000000000 11111111111111111111111111111111111111100000000000 11111111111111111111111111111111111111000000000000 11111111111111111111111111111111111110000000000000 11111111111111111111111111111111111100000000000000 11111111111111111111111111111111111000000000000000 11111111111111111111111111111111110000000000000000 11111111111111111111111111111111100000000000000000 11111111111111111111111111111111000000000000000000 11111111111111111111111111111110000000000000000000 11111111111111111111111111111100000000000000000000 11111111111111111111111111111000000000000000000000 11111111111111111111111111110000000000000000000000 11111111111111111111111111100000000000000000000000 rejudge me please, I also get AC using brute_force and can't pass this test case Edited by author 15.11.2016 07:21 now 13 problems with 10W+ rating... |
| What's wrong with my code? Че не так ? (C++) | Zalkar | 1001. Reverse Root | 14 Nov 2016 16:26 | 2 |
#include<iostream> #include<iomanip> #include<cmath> using namespace std; int main() { long long n,i=0,c=0; double a[100001]; while(cin>>n){ a[i]=sqrt(n); i++; c++; } for(int i=c-1; i>=0; i--) cout<<fixed<<setprecision(4)<<a[i]<<endl; system("pause"); return 0; } The size of the input stream does not exceed 256K |
| Please send some examples | Nataraj | 2024. Adventure Time | 14 Nov 2016 09:52 | 4 |
Could somebody who solved this problem send some examples of tests and solutions? I thought that I wrote a correct algorithm, that summarise number of stones of each type, then sort it and then check how many permutations of the last one that makes it equal to K, there is and calculate a number of possibilities. But I get error on Test 3. Or may be I did not understood the task, I found the bug, but now I get wrong answer for test 26 Finally solved it. The last bug was to find a function that calculates factorial coefficients (ncr) without going to big numbers. What is the principle of this function? |
| TEST #10 | James Chan | 1014. Product of Digits | 12 Nov 2016 22:59 | 2 |
Anybody can help me with TEST #10. Just give me an example Thank you very much. 222 ans is--> -1 bcuz 222/6= 37 ;but 37 is prime so ans -1 |
| No subject | Andrey | 1493. One Step from Happiness | 12 Nov 2016 19:26 | 1 |
#include <iostream> long int a,b,c,d,e,f,n,z,x,a1,a2; using namespace std; void main() { cin >>a; n=a%10; f=a%100; f=f/10; e=a%1000; e=e/100; d=a%10000; d=d/1000; c=a%100000; c=c/10000; b=a%1000000; b=b/100000; if ((n==9)||(f==9)||(e==9)) { z=(e+f+n)+1%10; } else { z=e+f+n; } if ((d==9)||(c==9)) { x=(b+c+d)+1%10; } else { x=b+c+d; } a1=z-x; a2=x-z; if ((a1==1)||(a2==1)) { cout <<"Yes"; } else { cout <<"No"; } } |
| A few tests that helped me to find an error. | Victor Barinov (TNU) | 1058. Chocolate | 12 Nov 2016 02:53 | 3 |
4 0 0 1 0 0 1 -1 1 0.7071 3 0 0 1 0 0 1 0.6436 3 -1 0 1 0 0 1 0.9102 Thank you. But... C:\Casual\Task1058>task1058.exe <test12.txt 0.7071 C:\Casual\Task1058>task1058.exe <test13.txt 0.6436 C:\Casual\Task1058>task1058.exe <test14.txt 0.9102 I can hardly ever understand anything. My program cannot pass test #3. |
| Tests | Islom(TUIT Urgench) | 1425. Queen 2 | 11 Nov 2016 18:24 | 1 |
Tests Islom(TUIT Urgench) 11 Nov 2016 18:24 Test#1 3 3 1 2 3 ans:27 Test#2 2 6 1 3 ans:36 Test#3 3 6 3 4 5 ans: 180 Test#4 1 5 3 ans:5 Test#5 1 2 1 ans:1 Test#6 3 2 1 2 2 ans:4 |
| JAVA, plz help | fletcher6847 | 2002. Test Task | 11 Nov 2016 13:00 | 2 |
import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Timus2002 { public static void main(String[] args) { Map<String, String> map = new HashMap<>(); Scanner sc = new Scanner(System.in); String[] s = new String[105]; ArrayList<String> logged = new ArrayList<>(); int n = Integer.parseInt(sc.nextLine()); for (int i = 0; i < n; i++) { s[i] = sc.nextLine(); } for (int i = 0; i < n; i++) { String[] mas = s[i].split(" "); if(mas[0].equals("register")){ if(map.containsKey(mas[1])){ System.out.println("fail: user already exists"); continue; } map.put(mas[1], mas[2]); System.out.println("success: new user added"); } String login = mas[1]; if(mas[0].equals("login")){ String pass = mas[2]; if(!map.containsKey(login)) { System.out.println("fail: no such user"); continue; } String value = map.get(login); if(!value.equals(pass)) System.out.println("fail: incorrect password"); if(value.equals(pass)) { if (!logged.contains(login)) { logged.add(login); System.out.println("success: user logged in"); } else System.out.println("fail: already logged in"); } } if(mas[0].equals("logout")) { if (!map.containsKey(login)) System.out.println("fail: no such user"); if (!logged.contains(login)) System.out.println("fail: already logged out"); else { System.out.println("success: user logged out"); logged.remove(login); } } } } } It works, but cant pass the test |
| WA # 10? | muhiddin | 1881. Long problem statement | 11 Nov 2016 12:30 | 5 |
Pleae help. what is this test? Any input i get correct answer in my compiler.But here i get WA #10 2 4 5 a! a! a! a! a! try this, correct answer is 3, not 2 Thanks, I couldn`t understand where is a mistake) Why is it true? It should be 2, not 3! I got an AC after changing the input bufsize from 100 to 101. |
| TEST | Murodjon (TUIT Urgench) | 1809. Chapaev and Potatoes | 10 Nov 2016 10:52 | 1 |
TEST Murodjon (TUIT Urgench) 10 Nov 2016 10:52 Try this 1 1 2 2 3 3 4 4 2 change |
| No subject | Md Shohel Rana | 1106. Two Teams | 10 Nov 2016 09:22 | 2 |
how can i see my current accepted submission rank???? http://acm.timus.ru/rating.aspx?space=1&num=1106Non language-specific rating; from there, you can select a language for a language-specific rating. However, it doesn't appear you have this task submitted, at least not from the account you've posted this message. Edited by author 10.11.2016 09:24 |
| What wrong answer#3 | Shohruh_1999 | 2023. Donald is a postman | 10 Nov 2016 08:57 | 1 |
#include<iostream> using namespace std; int n,i,k,t,j; string a[10000],b[10000],c[10000],d[10000]; int main(){ a[1]="Alice"; a[4]="Phil"; a[7]="Phoebus"; a[2]="Ariel"; a[5]="Peter"; a[8]="Ralph"; a[3]="Aurora"; a[6]="Olaf"; a[9]="Robin";
b[1]="Bambi"; b[4]="Mulan"; b[7]="Silver"; b[2]="Belle"; b[5]="Mowgli"; b[8]="Simba"; b[3]="Bolt"; b[6]="Mickey"; b[9]="Stitch";
c[1]="Dumbo"; c[4]="Kuzko"; c[7]="Tarzan"; c[2]="Genie"; c[5]="Kida"; c[8]="Tiana"; c[3]="Jiminy"; c[6]="Kenai"; c[9]="Winnie"; cin>>n; for(i=1; i<=n; i++) cin>>d[i]; for(i=1; i<=n; i++) { for(j=1; j<=9; j++) if(d[i]==a[j]){ if(t==0) k+=0; if(t==1) k+=1; if(t==2) k+=1; if(t==3) k+=2; t=1; break; } for(j=1; j<=9; j++) if(d[i]==b[j]){ if(t==0) k+=0; if(t==1) k+=1; if(t==2) k+=1; if(t==3) k+=1; t=2; break; } for(j=1; j<=9; j++) if(d[i]==c[j]) { if(t==0) k+=0; if(t==1) k+=2; if(t==2) k+=1; if(t==3) k+=1; t=3; break; } } cout<<k; } |
| what's wrong? | Ehcalahim | 1106. Two Teams | 9 Nov 2016 23:56 | 1 |
what's wrong with this code: #include <iostream> #include <vector> #include <list> using namespace std; int ar[102][102],viz[102]; int n; list <int> a; int dfs(int s) { viz[s] = 1; for (int i=1;i<=n;i++) { if (ar[i][s] && !viz[i]) {dfs(i); }//a.push_back(i);} } return 0; } int main() { cin >> n; int z; for (int i=1;i<=n;) { cin >> z; if (z == 0) i++; else ar[i][z] = 1; } dfs(1); for (int i=1;i<=n;i++) if(!viz[i]) a.push_back(i); cout << a.size() << endl; for (int n : a) { cout << n << " "; } return 0; } maybe i didn't understand problem properly,some help? |
| Help requested | Erast V. Kunenkov | 1134. Cards | 8 Nov 2016 17:36 | 11 |
Here is my solution and used test cases. I don't understand why I always get WA. 8-( Test 1. 5 4 2 0 1 2: NO Test 2.5 4 2 0 1 5: YES Test 3. 5 4 2 0 3 5: YES Test 4. 5 4 2 0 3 4: YES Test 5. 5 5 2 0 3 4 5: YES Test 6. 5 5 2 0 2 4 5: YES Test 7. 5 6 2 1 2 4 5 0: NO Test 8. 5 4 1 2 2 3: YES Test 9. 5 5 1 2 3 4 3: YES Test 10. 5 5 1 1 0 3 4: NO Test 11. 5 3 0 0 1: NO Test 12. 5 3 0 1 1: NO Test 13. 5 3 1 2 2: YES Test 14. 5 3 1 1 2: YES Test 15. 5 3 4 4 5: NO Test 16. 5 3 3 4 4: YES Test 17. 5 3 4 5 5: NO Test 18. 5 3 3 4 5: YES Test 19. 2 2 1 1: YES Test 20. 2 2 2 2: NO Source code: [code deleted] Edited by moderator 13.02.2007 20:57 If the num of cards is lower than m i think that the asnwer should be NO 2.5 4 2 0 1 5 YES? Edited by author 19.01.2007 12:34 I'm not very good in C, and i don't undrstand your source) But my idea is very simple. Store in array number of repeats, increment a[0] and a[n] (because it's only one card with this numbers) and find in array sequence 2 1 1 .. 1 1 2 that's all) Edited by author 22.04.2009 22:45 i think so.i think that test#9 may be wrong.or i made mistake while reading the problem... tell the truth,i don't really understand the problem .. I don't understand Test 5. 5 5 2 0 3 4 5: YES Why? first 5 so take 5 or 6 second 5 so take 5 or 6 so take 5 and 6 ... last 5 so take 5 or 6 again, but 5 and 6 were taken, so NO help me, please for the 1st and the 2nd 5 means n and m without meaning the number which was took. here are test right Edited by author 31.12.2012 02:08 Edited by author 31.12.2012 02:08 Edited by author 31.12.2012 02:08 |
| idea | dustbite | 1731. Dill | 8 Nov 2016 09:43 | 1 |
idea dustbite 8 Nov 2016 09:43 there are n * m possible sums. to find a solution, we can try to create such vectors such that all n * m sums are different. Suppose the 1st vector is 1 2 3 ... n Then the first element of next vector is taken to be n + 1(we require all unique). Now we need to find the next element while making all n*p sums different, where p is the size of the 2nd vector. n+1 1 2 3 ... n initially all sums(n+2 to 2n+1) are distinct. Now we need to add new element such that smallest possible new sum is greater than the previous sum i.e. if new element is p p+1>2n+1 or p >= 2n + 1 in general p+1>prev+n p>=prev+n |
| I Have WA#4 | xurshid_n | 1926. The Tournament of Intelligences | 8 Nov 2016 00:03 | 1 |
what is wrong here? for (int i =0; i< 15;++i) { int p = primes[i]; if ( c % p == 0) { unsigned long long M = c / p; unsigned long long M_inv = inverse[i][ M % p ] ; unsigned long long h = M_inv * m[ i ]; // r = (r + h * M ) % c unsigned long long high_M = (M >> 32 ) & 0xFFFFFFFFULL; unsigned long long low_M = ( M & 0xFFFFFFFFULL); // h * M= h * (high_M * 2^32 + low_M) unsigned long long high_h = high_M * h; unsigned long long e = (high_h >> 32) & 0xFFFFFFFFULL; unsigned long long f = (high_h & 0xFFFFFFFFULL); // high_h = e*2^32 + f // h*M = h*(high_M*2^32 + low_M) = high_h * 2^32 + low_M * h = // = (e*2^32 + f)*2^32 + low_M * h = e*2^64 + f*2^32 + low_M * h e = (e << 48) % c; e = (e << 3 ) % c; e = (e << 3 ) % c; e = (e << 3 ) % c; e = (e << 3 ) % c; e = (e << 3 ) % c; e = (e << 1 ) % c; e = (e + (f << 32) ) % c; e = (e + low_M * h ) % c;
r = (r + e ) % c; } } |
| Can you help me!? Why this approach is correct? | Alibi | 2025. Line Fighting | 7 Nov 2016 22:50 | 2 |
You have to divide the participants into equal teams (rounded) For example, for "15 10" test - (1, 1, 1, 1, 1, 2, 2, 2, 2, 2) Good luck :) Well I don't understand this topic CLEARLY but I can trace some steps towards the final solution. Let's fix a possible team distribution i.e. number of teams Then, we need to find the best possible distribution to maximize the product For eg for 4 teams a1,a2,a3,a4 will be the team distribution a1+a2+a3+a4=n now we need to maximize the function f(a1,a2,a3,a4)=a1a2+a1a3+a1a4+a2a3+a2a4+a3a4 under the constraint a1+a2+a3+a4=n, which can be done using lagrangian multiplier. g(a1,a2,a3,a4)=f(a1,a2,a3,a4)+p(n-a1-a2-a3-a4) lets take derivative of the function g at a1 g'(a1) = a2+a3+a4 -p g'(a2) = a1+a3+a4 -p g'(a3) = a1+a2+a4 - p g'(a4) = a1+a2+a3 - p Equate all of them to zero a1+a2+a3=a2+a3+a4=a1+a3+a4=a1+a2+a4=p from 1st and second we find a1=a4 from 2nd and 3rd a2=a1 similarly we find a1=a2=a3=a4, all a's must be equal so a1+a2+a3+a4=n a1=n/4 In general a1=n/p, where p is the number of teams. When p is not divisible, we need to make all of them as equal as possible by distributing n % p. I don't understand lagrangian multiplier by heart(I have not tried to). But the tool works here. We can try bruteforcing all possible team numbers from 2 to k and find which is best. Edited by author 07.11.2016 22:51 |
| Why WA1? | ahmetov14 | 2031. Overturned Numbers | 7 Nov 2016 22:26 | 1 |
int n = in.nextInt(); int l = 0; if (n > 24) { out.print("Glupenky Pierre"); } else { for (int i = 1; i <= n; i++) { if (i / 5 == 0) l = 0; if (i / 5 == 1) l = 1; if (i / 5 == 2) l = 8; if (i / 5 == 3) l = 6; if (i / 5 == 4) l = 9; if (i % 5 == 0) l = l * 10; if (i % 5 == 1) l = l * 10 + 1; if (i % 5 == 2) l = l * 10 + 8; if (i % 5 == 3) l = l * 10 + 6; if (i % 5 == 4) l = l * 10 + 9; if (l/10==0) out.print("0"); out.print(l); out.print(" "); } } Edited by author 07.11.2016 22:26 Edited by author 07.11.2016 22:27 |
| Why I get WA? Pelase, help me!!!!!!! | Revenger and NSC | 1134. Cards | 7 Nov 2016 17:55 | 4 |
There is my code: Program t1134; Const MaxN=1000; Var Card : array[1..MaxN]of boolean; Numb : array[1..MaxN]of integer; Use : array[1..MaxN]of boolean; M,N,i,j : integer; ex : boolean; begin Read(N,M); if (M>N)or(m=0) then begin writeln('NO'); halt(0); end; for i:=1 to N do Card[i]:=false; for i:=1 to M do Use[i]:=false; for i:=1 to M do begin read(Numb[i]); if (Numb[i]<0)or(Numb[i]>n) then begin writeln('NO'); halt(0); end; end; for i:=1 to M do if Numb[i]=0 then begin Use[i]:=true; if Card[1] then begin writeln('NO'); halt(0); end; Card[1]:=true; end else if Numb[i]=n then begin Use[i]:=true; if Card[n] then begin writeln('NO'); halt(0); end; Card[n]:=true; end; for i:=1 to m-1 do if not(use[i]) then for j:=i+1 to m do if not(use[j]) then if numb[i]=numb[j] then begin if (card[numb[i]])or(card[numb[j]-1]) then begin writeln('NO'); halt(0); end; card[numb[i]-1]:=true; card[numb[i]]:=true; use[i]:=true; use[j]:=true; end; repeat ex:=true; for i:=1 to m do if not(use[i]) then if (card[numb[i]])or(card[numb[i]-1]) then begin if (card[numb[i]])and(card[numb[i]-1]) then begin writeln('NO'); halt(0); end; if card[numb[i]] then begin card[numb[i]-1]:=true; use[i]:=true; end else begin card[numb[i]-1]:=true; use[i]:=true; end; end; until ex; Writeln('YES'); end. 3 3 2 2 3 Maybe you forgot something, because the output of your program for this test case is 'YES'; hope this will help Good luck! > 3 3 > 2 2 3 > Maybe you forgot something, because the output of your program for > this test case is 'YES'; > hope this will help > Good luck! > i suppose the answer should be NO for that 2 2 means the 2nd and the 3rd had been taken, so the third number 3 is uncorrect 3 3 2 2 3 Maybe you forgot something, because the output of your program for this test case is 'YES'; hope this will help Good luck! |