Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | WA53 | r1d1 | 1809. Чапаев и картошка | 30 окт 2010 17:18 | 1 | WA53 r1d1 30 окт 2010 17:18 | | Why I have Time Limit Exceeded???? c++ | Hristian Hristov | 1104. Не спрашивай даму о возрасте | 30 окт 2010 17:06 | 6 | #include <iostream> #include <string> using namespace std; int main() { string a; long p=0,max=0,i; cin >> a; long n=a.size(); for(i=0; i<n; i++) { if(a[i]>='0' && a[i]<='9'){ p=p+(a[i]-'0'); if(a[i]-'0'>max) max=a[i]-'0'; } else { p=p+(a[i]-'A'+10); if(a[i]-'A'+10>max) max=a[i]-'A'+10;} } if(max==0) { i=0; cout << "2" << endl;} else { for(i=max+1; i<=36; i++) if(p%(i-1)==0){ cout << i << endl; break; }} if(i==37) cout << "No solution." << endl; return 0; } Because you read the whole string to a variable, and then loop through that string. You must use C. It's more quick . No C++. Just C. In the statements, string_length = 10^6, but your string_size can be maximum 256, write like this, and you will get AC : #include <iostream> #include <string> using namespace std; string a; long p,maxx,i,n; int main() { cin >> a; n=a.size(); for(i=0; i<n; i++) { if(a[i]>='0' && a[i]<='9'){ p=p+(a[i]-'0'); if(a[i]-'0'>maxx) maxx=a[i]-'0'; } else { p=p+(a[i]-'A'+10); if(a[i]-'A'+10>maxx) maxx=a[i]-'A'+10;} } if(maxx==0) { i=0; cout << "2" << endl;} else { for(i=maxx+1; i<=36; i++) if(p%(i-1)==0){ cout << i << endl; break; }} if(i==37) cout << "No solution." << endl; return 0; } No need to use complicated input styles. Just include cstdio as a header file and use scanf instead. You dont need to switch over to a C file. You can simply use C functions from C++. Regards Nitin 2 change code and AC:-) /* #include <iostream> #include <string> using namespace std; int main() { string a; long p=0,max=0,i; while(cin >> a)//1 { p=0;max=0;//2 long n=a.size(); for(i=0; i<n; i++) { if(a[i]>='0' && a[i]<='9'){ p=p+(a[i]-'0'); if(a[i]-'0'>max) max=a[i]-'0'; } else { p=p+(a[i]-'A'+10); if(a[i]-'A'+10>max) max=a[i]-'A'+10;} } if(max==0) { i=0; cout << "2" << endl;} else { for(i=max+1; i<=36; i++) if(p%(i-1)==0){ cout << i << endl; break; }} if(i==37) cout << "No solution." << endl; } return 0; } */ | | Wrong answer 6 | DnS [Samara SAU] | 1070. Местное время | 30 окт 2010 17:05 | 3 | If you got Wrong answer 6 then if (answer>5) answer=5; cout<<answer -- !!! Most Important!!! I have got AC when write it. Example 01.01 21.59 04.23 11.22 Answer: 5 true 7 hours (21-7=7+7), but you must write 5!!! good luck. :) I think you are not right. In this test the time difference between two airports is exaclty 5, and the flying lasts 2 hours. So, the first difference ~ -3 hours, and the second one ~ 7 hours. It's true)) There is a inconsistent problem situation. They should write date of flight. Sorry for my english. | | No subject | B-S42#-1Shipulin | 1804. Пулемётчицы в плей-офф | 30 окт 2010 13:16 | 1 | Edited by author 02.11.2010 21:17 | | why I always got WA on test #2? | ss | 1086. Криптография | 30 окт 2010 03:43 | 8 | I just find all 15000 prime numbers and put them in an array then writeln(a[n]) for each n isn't it correct? I just cannot understand Maybe you generate only small numbers, try to use array size 170001, and you'll get AC! I set 190000.some problem. where is the problem???this code fails in test#2 :( #include<stdio.h> #define size 150001 long a[size]; long p[size]; int main() { long i,j,k,m=0,n,t; a[0]=1; a[1]=1;
for(i=4;i<=size;i+=2) a[i]=1; for(i=3;i<=size;i+=2) { if(a[i]==0) { k=size/i; for(j=i;j<=k;j++) a[j*i]=1; } }
for(i=0;i<=size;i++){ if(a[i]==0) p[m++]=i; }
scanf("%ld",&t); while(t--){ scanf("%ld",&n); printf("%ld\n",p[n-1]); } return 0; } Use __in64 instead of long! you user java language for this problem first generate prime number and put it into a array prime[15000] and the scan the number ex. 10 and print prime[10] There is my i got AC import java.util.*; public class Main { public static long prm[] = new long[15001]; public static void main( String args[] ) {
Main obj = new Main(); obj.sieve(163841); Scanner in = new Scanner(System.in); int t=in.nextInt(); while(t>0) { t--; int n=in.nextInt(); System.out.println(prm[n]); } } public void sieve (int outerBounds) { long start = System.currentTimeMillis();
int N = outerBounds; boolean[] isPrime = new boolean[N + 1]; for (int i = 2; i <= N; i++) { isPrime[i] = true; } for (int i = 2; i*i <= N; i++) { if (isPrime[i]) { for (int j = i; i*j <= N; j++) { isPrime[i*j] = false; } } } int j=1; for (int i = 2; i <= N; i++) { if (isPrime[i]) { prm[j]=i; j++; } } } } here i user sieve method Edited by author 30.10.2010 03:44 Edited by author 30.10.2010 03:45 | | what is the first data? | tklist | 1030. Титаник | 29 окт 2010 21:28 | 1 | I aways WA,but I cannot find the error.Can someone help me? | | if you had WA 5 | Sxcyd | 1212. Морской бой | 29 окт 2010 07:44 | 1 | A very important problem that you may forgot.When you calculate the sum of the ship could placed,if we Sum:=(n-k+1)*m+(m-k+1)*n. It's wrong,because k may >n&m. There is a test: 6 2 1 1 1 2 H 4 You should output 2. Good Luck! | | HELP WITH IDEA!!! | Nurbek_[KTMU MANAS] | 1605. Дьявольская последовательность | 29 окт 2010 05:38 | 11 | Who has accepted this task, please help with idea. I have not anithing idea! Use log10 to compare 2^n and 10^k 2 svr: I don't understand what you mean ? What I should use formule or ...? This sequence representable in the form of partial sums apparent number, the amount of which is equal to 1 / 6 - to find the desired response should compare the full amount of partial, asked n. only math. -- по-русски: эта последовательность представима в виде частичных сумм очевидного ряда, сумма которого равна 2/3 - чтобы найти искомый ответ необходимо сравнить всю сумму с частичной, задаваемой n. чистая математика. I've accepted this problem using precalc. Just quick long arithmetics and some trick to make source file of size 4 Kb... I meant the formula a[n]=2/3+(-1)^(n-1)/(3*2^(n-1)) to svr: you are right, this formula is correct (I can prove it). But how to take benefit from this? Of course, using this this formula I can right brute force quick long arithmetics. But this algo will be TL. we should take log10 from abs(2/3-a[n]) ?? use also the formula: 2/3=0.666666+10^(-k)*2/3 I think problem is very interesting. I was trying to solve it in "programming way" for a long time, but all my attempts lead to TL on N > 10000 values. Finally I finished with completely mathematical solution. I think that description from my source can help someone so I'll left it here... /* * Let x[n] be n-th element of given sequence. * Following formula for x[n] can be simply proved: * x[n] = 2/3 + (1/3)/(2^(n-1)) if n - odd * x[n] = 2/3 - (1/3)/(2^(n-1)) if n - even * Let delta = (1/3)/(2^(n-1)) = 0.000XXXX.. (X - any digit) * We can simply find number of leading zeroes after * decimal point (befor XXX..) as: * k = floor[ Log10(3*2^(n-1)) ] or * k = floor[ Log10(3) + (n-1)*Log10(2) ] * Obviously answer always will be k or k-1. * Consider (k-1)-cases: * [1] N - odd (add delta): * A = (1/3)/(10^k) = 0.0003333... (repeat 0 k times) * If A <= delta - then addition will affect k-th digit * and answer will be k-1. * [2] N - even (subtract delta): * A = (2/3)/(10^k) = 0.0006666... (repeat 0 k times) * If A <= delta - then subtraction will affect k-th digit * and answer will be k-1. * Compare logarithms instead of comparing values themself. */ | | Wrong link in notification letter | Fyodor Menshikov | | 28 окт 2010 22:29 | 2 | I've received letter from judge@acm.timus.ru containing the following text: " ID: 2336619 Problem: 1604. Country of Fools Wrong verdict: Accepted New verdict: Wrong answer http://acm.timus.ru/status.aspx?space=1&num=1604&author=" I think after author and '=' there should be my author id. But it's missing. And I cannot see list of my submissions, instead I see list of recent submissions of the problem solutions. Fixed Vladimir Yakovlev (USU) 28 окт 2010 22:29 | | WA9 | Andrex | 1711. Кодовые имена | 28 окт 2010 18:22 | 1 | WA9 Andrex 28 окт 2010 18:22 please, help me... my code: #include <iostream> using namespace std; int main() { int n,m[16],k; char c[48][20],v[16][20],ch[3][20]; cin>>n; for(int i=0;i<n*3;i++) cin>>c[i]; for(int i=0;i<n;i++) { cin>>k; m[i]=k; } k=(m[0]-1)*3; if((strcmp(c[k],c[k+1])<=0)&&(strcmp(c[k],c[k+2])<=0)){strcpy(v[0],c[k]);} if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0)){strcpy(v[0],c[k+1]);} if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0)){strcpy(v[0],c[k+1]);} for(int i=1;i<n;i++) { k=(m[i]-1)*3; if((strcmp(c[k],c[k+1])<=0)&&(strcmp(c[k],c[k+2])<=0)) { strcpy(ch[0],c[k]); if(strcmp(c[k+1],c[k+2])<=0) { strcpy(ch[1],c[k+1]); strcpy(ch[2],c[k+2]); } else { strcpy(ch[2],c[k+1]); strcpy(ch[1],c[k+2]); } }
if((strcmp(c[k+1],c[k])<=0)&&(strcmp(c[k+1],c[k+2])<=0)) { strcpy(ch[0],c[k+1]); if(strcmp(c[k],c[k+2])<=0) { strcpy(ch[1],c[k]); strcpy(ch[2],c[k+2]); } else { strcpy(ch[2],c[k]); strcpy(ch[1],c[k+2]); } }
if((strcmp(c[k+2],c[k])<=0)&&(strcmp(c[k+2],c[k+1])<=0)) { strcpy(ch[0],c[k+2]); if(strcmp(c[k],c[k+1])<=0) { strcpy(ch[1],c[k]); strcpy(ch[2],c[k+1]); } else { strcpy(ch[2],c[k]); strcpy(ch[1],c[k+1]); } }
if(strcmp(v[i-1],ch[0])<=0) { strcpy(v[i],ch[0]); } else { if(strcmp(v[i-1],ch[1])<=0) { strcpy(v[i],ch[1]); } else { if(strcmp(v[i-1],ch[2])<=0) { strcpy(v[i],ch[2]); } else { cout<<"IMPOSSIBLE"; return 0; } } } } for(int i=0;i<n;i++) { cout<<v[i]<<endl; } return 0; } | | WA#6 doesn't matter if you're black or white? | Micheal Jackson | 1788. О пользе зонтов | 28 окт 2010 14:53 | 1 | | | Da io nu stiu cum se face | Micheal Jackson | 1788. О пользе зонтов | 28 окт 2010 14:49 | 5 | Am nevoie e ajutor, va rog io \\warn Edited by author 28.10.2010 14:45 da mah, io is cantaretz, si acuma tre sa fac probleme de pe timus. dami si mie te rog io fain, raspunsu sau un indiciu Ce warn o luat fratzica =)) | | Wrong tag | Fyodor Menshikov | 1427. SMS | 28 окт 2010 01:07 | 1 | Tags: dynamic programming But most solution of the problem use a greedy algo | | 1427 | Roumed | 1427. SMS | 28 окт 2010 01:07 | 3 | 1427 Roumed 17 янв 2007 20:47 On the 11-(10-1)th of Febr(10-2)uary, 2006(10-3) the conte(10-4)st "Timus (10-5)Top Coders(10-6): First Ch(10-7)allenge" i(10-8)s held! The exemple of this problem is wrong,isn't it? Re: 1427 Kurpilyansky Eugene (USU) 17 янв 2007 21:35 Example is correct: On the 11-<1>th of February<2>, 2006 the <3>contest "T<4>imus Top Coders<5>: First Ch<6>allenge" i<7>s held!<8> Re: 1427 rawe (Vologda ML) 28 окт 2010 01:07 you are very very very bad man, the correct answer to example is: On the 11-<1-10>th of February<2-14>, 2006 the<3-10> contest "<4-10>Timus Top Coder<5-15>s: First C<6-10>hallenge" <7-10>is held!<8> in your example ", 2006 the " 11 simbols!!! after your explain I think that spaces in begin of sms must delete and I always have WA4! | | WA 10. Can you give me some tests?(+) | Programmer | 1521. Военные учения 2 | 27 окт 2010 19:31 | 2 | Sorry , have found bug. Edited by author 24.04.2009 03:03 Anybody, wright test 10, please... | | Who can explain the standard input and output? Why 'YES"? | qaztz | 1191. Держи вора! | 27 окт 2010 18:09 | 3 | I can't understand it, either. Edited by author 25.05.2010 08:31 hi,standard input has keyboard. and standard output has monitor. | | WA Test 25 | SK1 | 1182. Team Them Up! | 27 окт 2010 17:31 | 17 | I have WA on the test 25. Who can help me? I have the tests. If you want them , post your mail adress. This is mine: charles8827@163.com Thank you very much. Gheorghe Stefan I got WA on test 15.. Please post the tests to me. Thank you very much. My e-mail : happy123456@hotmail.com Edited by author 18.05.2004 16:47 I find the tests. And I find my mistake. I got AC . :) Edited by author 18.05.2004 16:57 WA 15 Vampire 26 окт 2004 18:26 Here is my e-mail:sanguokuang@yahoo.com.cn Please send me the tests.Thenk you! Please give me the tests. My e-mail : alexpopa@shock.ldc.ro I found the tests on the web, I tested my program an it shows the correct answers. Can anybody help me ? Could anyone tell me where I can get the tests?Thank you. My program passes all tests from NEERC, but has WA18 on Timus. I can't find my mistake. :( I Wa on Test 25, I need the Tests. Could you send it to me? Thank you. My E-mail: Skyfish_cdq@hotmail.com I have the tests. If you want them , post your mail adress. I Wa on Test 25. Could you send it to me? Thank you. alvinhuang1105@163.com Just google "NEERC 2001"... | | Easy solution | espr1t | 1790. В поисках Истины | 27 окт 2010 17:07 | 15 | Interestingly enough the problem can be solved with simple simulation. Just simulate the process, choosing random directions and random initial positions while you are within the time limit and you will get accepted. I really doubt this is the correct solution, so I was wondering what is the real one? There is very simple O(m) solution - just use your algorithm for solution of previous problem. I've got WA#9. My algo is: first I generate the possible answers in both directions (strating from 1 and n) with algorithm from the previous problem, and with KMP I'm searching the input array for match, also I added special cases for 2 (1 1 and 2 2) and for 3 (2 2). Edited by author 20.10.2010 04:44 To KALO: Try this test 5 10 1 2 3 4 5 1 2 3 4 5 To KALO: Try this test 5 10 1 2 3 4 5 1 2 3 4 5 If N is odd = then sequence are 1..N 1..N 2..N-1 N-1 else the sequence is 2..N-1 N-1.. 2 I'm right? Edited by author 20.10.2010 17:04I don't understand you. As I know, jury's solution don't use misterious knowledges about any sequences. =) O(m) solution doesn't use them as well =) No, I was talking about general logic of my algorithm. Of course, it is incorrect to search for some predefined sequence in the answer. For example, for m=5 general algorithm gives sequence like 1 2 3 4 5 1 2 3 4 (or something like that), but possible answer is 2 2 4 4 4 4 3 2. if m = 5, 2 2 4 4 4 4 3 2 can't be the answer imagine original is on 4th pedestal you touch 2 orig move 4 -> 3 you touch 2 orig move 3 -> 2 you touch 4 orig move 2 -> 3 you touch 4 orig move 3 -> 2 you touch 4 orig move 2 -> 3 you touch 4 orig move 3 -> 2 you touch 3 orig move 2 -> 3 you touch 2 orig move 3 -> 4 you didn't catch the orig! if the sequence has 2 * k numbers suquencially you can take only 2 if 2 * k - 1 you can take 1 (I think) example 2 2 2 2 3 3 3 5 6 --> 2 2 3 5 6 Edited by author 20.10.2010 22:39 Idea: Game of two person and bacward analysis from the end Example: 3 3 1 2 3 3: 1,2-win; 3- fail 2:1,3-win(1->2,3->2) 2- fail 1:2-win(2->1)1,3-fail so win:2->1->2 Edited by author 25.10.2010 14:41 I understand ur algo but I think it's O(n*m). Isn't It? Won't it get TL Yes. But pattern of failed states exits and it's maitaining costts O(1) on eaxh of n steps. what if n = 10^5 and m = 10^5 sequence is like this 4 6 4 6 4 6 4 6 4 6 . . . I think at this test the length of failed pattern is 1 all the time and time is O(n, m) again. Or I didn't understand your previous massage rightly? To Alexander Georgiev: now your solution gets wa51. do you happy? :) Edited by author 20.10.2010 16:37 Yep. It is interesting - how many brute force solutions fail after new tests :) Sort of =) NOW I have to write a real solution :) | | what is wrong with my code | AsgarJavadov | 1506. Столбцы чисел | 27 окт 2010 16:34 | 3 | I get WA#1 here is my code #include <cstdlib> #include <iostream> using namespace std; int i, j, n, k, say, a[101]; int main(int argc, char *argv[]) { cin >> n >> k;
for( i = 0; i < n ; i++ ) cin >> a[ i ]; if( n%k != 0) say = n/k + 1; else say = n/k;
for( j = 0; j < say; j++ ){ cout << a[ j ]; i = j + say; while( i < n){
cout <<" "<< a[ i ]; i += say; } if( j < say-1 ) cout << endl; }
return 0; } Output: The width of each column must be 4 symbols; the numbers must be aligned to the right edge and padded with spaces to the required width hi.you have 3 error's 1.you get 1 test case,but question has t test case. you can add while(cin>>n>>k){...} to het t,test case,t>0; 2.you end of ant test case add cout<<endl; 3.to any answer printf(" %3d",a[i]); good luck. | | Which of these formulas correct for this problem? | airibo | 1776. Праздничный фейерверк | 27 окт 2010 16:24 | 1 | Which of these formulas correct for this problem 1. M(A) + M(B) - M(AB) 2. M(A)*M(B/A) |
|
|