Common Board| Show all threads Hide all threads Show all messages Hide all messages | | HELP ME PLEASE! | KOTMAKRUS | 1083. Factorials!!! | 13 Nov 2013 16:51 | 1 | I have 1 test runs but on the server WA test 1!!??? program pro; var n,k,t:byte; s:string; sum:integer; BEGIN read(n,s); t:=1; k:=length(s)-1; if n mod k=0 then begin sum:=n; while n-t*k>0 do begin sum:=sum*(n-t*k); t:=t+1; if sum*(n-t*k)<0 then break; end; sum:=sum*k; end else begin sum:=n; while n-t*k>0 do begin sum:=sum*(n-t*k); t:=t+1; if sum*(n-t*k)<0 then break; end; sum:=sum*(n mod k); end; write(sum); END. 9 !! My program write 945 and why WA 1?????? | | What's wrong? | Fatum | 1068. Sum | 13 Nov 2013 14:25 | 1 | #include <iostream> using namespace std; int main(){
int a = 0; int b = 1; int c = 0; int k = 0;
cin >> a;
if(a > b){ k = 1;
for(; b <= a; b = b + k){
c += b;
}
}
else if(a < b){
k = -1;
for(; b >= a; b = b + k){
c += b;
}
}
cout << c; } | | Tests OK :) | pperm | 1985. Prime Square | 13 Nov 2013 13:39 | 3 | Edited by author 19.10.2013 16:35 Edited by author 19.10.2013 16:35 if n=10 then first column is that: 2 3 4 5 6 7 10 11 12 13 | | WA#32 | rydah | 2008. Swifty | 13 Nov 2013 04:11 | 4 | WA#32 rydah 11 Nov 2013 21:34 AC'ed authors, how could you fix this? Re: WA#32 Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 12 Nov 2013 00:57 Try to do all calculations in integer numbers I even replaced all the doubles with integers. But the result is the same. Re: WA#32 Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 13 Nov 2013 04:11 In my formula, overflow is possible even in long long, if computed straightforwardly. So, check that in your algo no overflow occurs. | | Why TL 11? | yutr777 | 1998. The old Padawan | 12 Nov 2013 23:21 | 6 | #include <stdio.h> #include <vector> #define pb push_back #define For(i,n) for(int i=0;i<n;i++) using namespace std; int main() { int n,m,k; vector < int > w; vector < int > v; scanf("%d%d%d",&n, &m, &k); For(i,n) { int x; scanf("%d", &x); w.pb(x); } For(i,m) { int x; scanf("%d", &x); x--; v.pb(x); } int ind=0; int tek=0; int ans=0; long long i=0; vector < int > solve; while (true) { if (ind<v.size() && i==v[ind]) { int kol=0; while (kol<=k && solve.size()>0) { w.pb(solve[solve.size()-1]); solve.pop_back(); kol+=w[w.size()-1]; } ind++; i++; continue; } solve.pb(w[0]); w.erase(w.begin()); i++; if (w.size()==0 || solve.size()==n)break; } printf("%d", i); } I have WA 11. My solution very similar to yours. I don't have any idea what is wrong. BTW. If you use long long, you must use %lld in printf instead %d. #include <stdio.h> int n,m,k; int w[10000]; int t[10000]; long long d; void swap(int i, int j) { int t; t = w[i]; w[i] = w[j]; w[j] = t; } int caving(int i) { int s = 0; int c = 0; int j; while ((s <= k) && (i > 0)) { i--; s += w[i]; c++; } /*for (j = 0; j < c/2; j++) { swap(i+j,i+c-j-1); }*/ return c; } int main() { int i,j; int cw, ct; #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif scanf("%d %d %d\n", &n, &m, &k); for (i = 0; i < n; i++) scanf("%d", &w[i]); for (i = 0; i < m; i++) scanf("%d", &t[i]); cw = 0; ct = 0; d = 0; do { d++; if ((ct < m) && (t[ct] == d)) { ct++; cw -= caving(cw); } else cw++; } while (cw < n); printf("%lld\n", d); return 0; } Hello, Kot! > int w[10000]; > int t[10000]; >> 1 ≤ n, m ≤ 10^5 I think yon need [100000] arrays. I had a step-by-step solution which caused TL 11. I've improved it to event-by-event solution but nothing changed. I translated it from Java to Visual C 2010 using your data loader and got WA11. Replaced w[10^4] by w[10^5] - and finally I've got TL11. I don't have any good idea and wonder about better algorithm or a bug which causes an endless loop... Could you try to fix it and write your solution result? Brute force solution works fine after some optimizations. Look at n and m limits - it is possible that Luke will drop same stones more than once. Finally my solution has been accepted. It's definitely a brute force one, but using optimization for all loops, which can be run undefined number of times. did you use binary search in your solution? | | Question | Itachi Uchiha | 2000. Grand Theft Array V | 12 Nov 2013 22:29 | 4 | "Each player has his own specified starting position", means that the starting positions of the players is different? Yes, that actually means it. You could see both positions in the last string of input. Re: Question Kungurtsev [USU][Psych Up club] 9 Nov 2013 16:41 No, in test 3, they both start in the same position. | | Only for uzbek | TUITUF_Bahrom | 1792. Hamming Code | 12 Nov 2013 19:55 | 4 | if((a[2]+a[3]+a[4])%2==a[5] && (a[1]+a[3]+a[4])%2==a[6] && (a[2]+a[1]+a[4])%2==a[7]) shu bajarilguncha ketma-ketlikni o'zgartirib borasiz 0 bo'lsa 1 va aksincha 1 bo'lsa 0 Masalan: 0 1 0 1 1 0 1 for petal 0 1 0 1 1 0 1 1 0 1 for petal 0 0 1 0 0 0 1 1 0 1 for petal 1 1 1 0 1 1 1 1 0 1 for petal 1 0 0 0 1 0 0 1 0 1 for petal 1 0 1 Edited by author 30.09.2013 14:39 Mana tayyor kod!!! [code deleted] Edited by Muzaffardjan Karaev M.K _77 )))xD 11.11.2013 11:11 Edited by author 12.11.2013 19:58 Edited by moderator 24.11.2019 12:42 | | Can't understand the test case | BUET_Bats | 1994. The Emperor's plan | 12 Nov 2013 17:59 | 2 | Can anyone please describe the test case? How can it be as low as 0.66667? - First night one good senator dies. We have 2 good senators and 1 spy. - First day senators choose to kill 2 people. They have a 66.6% chance that they get the spy and a good guy remains, 33.3% chance that the spy lives. | | AC | Aguero -=Yaroslavl SU #2=- | 1120. Sum of Sequential Numbers | 12 Nov 2013 16:44 | 1 | AC Aguero -=Yaroslavl SU #2=- 12 Nov 2013 16:44 Я один раскладывал 2*n на всевозможные множители?) | | Question | BUET_Sievers | 2000. Grand Theft Array V | 12 Nov 2013 13:11 | 3 | "At some moment of time two players can be located in the same cell." If this occurs, who will take the number in that cell? If both of them can take,then they can meet at some point and simultaneously take the number.That will maximize their score. They move in turns, not simultaneously, so even if they end up in one cell one of them (player one) must have stepped there first and therefore he must have taken the points from that cell. Thanks []zhi(Bozhin Katsarski) | | Test 11 | letsifer0 | 2008. Swifty | 11 Nov 2013 17:03 | 1 | Test 11 letsifer0 11 Nov 2013 17:03 I have WA#11, though my decision is consisted only from integer numbers. What is possible problem? Edited by author 11.11.2013 17:03 Edited by author 11.11.2013 17:04 Edited by author 11.11.2013 17:04 | | WA28....Please Help me!! | ZiV | 1299. Psylonians | 11 Nov 2013 14:43 | 3 | My program passed all tests from forum, but It gets WA28 Here is my code: Var ygol,arm,otkl,energy,us,ensrus,enemys,ensrzapas : int64; s : string; Function Min(x,y : int64):int64; Begin if x > y then Min := y Else Min := x; End; Procedure Oxrana; Begin if enemys = 0 then Writeln('STOP') Else if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else if ygol > 0 then Writeln('LEFT ',Min(100,energy)) Else Writeln('RIGHT ',Min(100,energy)); End; Procedure Atack; Begin if us*ensrus > enemys*ensrzapas*3 then if Abs(ygol) < 10 then Writeln('FIRE ',Min(20,arm)) Else Writeln('FRONT ',Min(100,energy)) Else if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else Writeln('BACKWARD ',Min(100,energy)) End; Procedure Defence; Begin if enemys*20 >= Arm then if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else Writeln('BACKWARD ',Min(100,energy)) Else Oxrana; End; Procedure Patrul; Var t : longint; Begin t := otkl; if otkl < 0 then Otkl := Otkl+360; if enemys > 0 then Defence Else if (Otkl>=160) and (otkl <= 200) then Writeln('BACKWARD ',Min(100,energy)) Else if ((otkl >= 0) and (otkl <= 20) or (otkl >= 340) and (otkl <= 360)) then Writeln('FRONT ',Min(100,energy)) Else if t > 0 then Writeln('LEFT ',Min(100,energy)) Else Writeln('RIGHT ',Min(100,energy)); End; BEGIN Readln(Energy,Arm); Readln(s); Read(enemys,ensrzapas,ygol); if Pos('A',s) <> 0 then Begin Read(us,ensrus); Atack; End; if Pos('D',s) <> 0 then Defence; if Pos('G',s) <> 0 then Oxrana; if Pos('P',s) <> 0 then Begin Read(otkl); Patrul; End; END. This test, please: 4 100 P 0 123 45 128 I hope it'll help you! :))) | | My Solution Here: | Destiny | 1224. Spiral | 11 Nov 2013 13:42 | 10 | program spiral; var n,m,r:real; begin readln(n,m); if m>=n then begin if n=1.0 then r:=0.0 else if n=2.0 then r:=2.0 else if frac(n/2)<>0 then r:=4.0*trunc(n/2) else r:=2.0*(n-1); end else begin if m=1.0 then r:=1.0 else if m=2.0 then r:=3.0 else if frac(m/2)<>0 then r:=4.0*trunc(m/2)+1.0 else r:=2.0*m-1.0; end; writeln(r:0:0); end. const{only 49K) maxn=11; var a:array[0..maxn]of 0..9; n,m:longint; i,j,s:integer; ok:boolean; begin fillchar(a,sizeof(a),0); readln(n,m); ok:=false; if n>m then begin n:=m;ok:=true;end; n:=n-1; i:=maxn+1; while n<>0 do begin i:=i-1; a[i]:=n mod 10; n:=n div 10; end; if ok then j:=1 else j:=0; for i:=maxn downto 1 do begin s:=a[i]*2+j; a[i]:=s mod 10; j:=s div 10; end; i:=0; while (a[i]=0)and(i<>maxn) do i:=i+1; for j:=i to maxn do write(a[j]); end. var m,n,y:real;b:boolean; begin readln(m,n); b:=false; if m>n then begin y:=m;m:=n;n:=y;b:=true end; if m=0 then begin writeln(0);halt;end; if frac(m/2)<>0 then y:=int(m/2)*4 else y:=int((m-1)/2)*4+2; if b then writeln(y+1:0:0) else writeln(y:0:0); end. #include <stdio.h> #include <math.h> int main(void) { unsigned int n, m, answer; scanf("%u %u", &n, &m); if (m >= n) answer = 2 * (n - 1); else answer = 2 * (m - 1) + 1; printf("%u\n", answer);
return 0; } Ok, same solution after some thinking. And it is working, just remember about huge numbers you are getting in the input #include <iostream> using namespace std; int main() { long long nN, nM; cin >> nN >> nM; if(nM >= nN) cout << 2*(nN-1); else cout << 2*(nM-1)+1; return 0; } Edited by author 12.11.2008 20:43 Edited by author 12.11.2008 20:44 Shortest sol (C language): main() { unsigned n, m; scanf("%u%u", &n, &m); printf("%u", n <= m ? 2 * n - 2 : 2 * m - 1); } #include <iostream> using namespace std; long long n,m; int main() { cin>>n>>m; if (m>=n) cout<<2*(n-1); else cout<<2*(m-1)+1; } My Solution program Ural1224; var n,m:int64; begin readln(n,m); if n<=m then writeln(n shl 1-2) else writeln(m shl 1-1); end. import java.io.*; import java.util.*; public class www { public static void main(String[] args) throws IOException{ PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(System.in); long n = in.nextInt(); long m = in.nextInt(); out.println(m>=n ? 2*n-2 : 2*m-1); in.close(); out.close(); } } Edited by author 27.08.2013 23:07 ee munaqa bo'mag'ur masalaga bosh qotirish shartmi? | | Wrong answer (Java) | Vombat | 1001. Reverse Root | 11 Nov 2013 04:51 | 1 | При компиляции примера выдает ответы такие как указаны в примере. Но при добавлении на сайт выдает ошибку. Не могу понять почему. Подскажите пожалуйста в чем проблема? import java.io.*; import java.math.BigDecimal; public class SqrtDif {
public static void main(String[] args) throws IOException { new SqrtDif().run(); }
PrintWriter out;
void run() throws IOException { out = new PrintWriter(new OutputStreamWriter(System.out)); byte bKbd[] = new byte[256]; int iCnt = 0; String szStr; try { iCnt = System.in.read(bKbd); } catch (IOException ex) { System.out.println(ex.toString()); } szStr = new String(bKbd, 0, iCnt); String[] Str = szStr.trim().split("\\D+"); double dStr; int i = Str.length-1; while (i>=0) { dStr = Double.parseDouble(Str[i]); BigDecimal bigDecimal = new BigDecimal(Math.sqrt(dStr)); bigDecimal = bigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP); out.print(bigDecimal.toPlainString()+"\r"); i--; } out.flush(); } } | | TEST 22 | rydah | 2008. Swifty | 11 Nov 2013 00:08 | 4 | I got WA#22. What is possible problem here? Re: TEST 22 Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 10 Nov 2013 20:03 Precision issues are quite possible in this problem - so, try to solve it in integer numbers. Re: TEST 22 Kungurtsev [USU][Psych Up club] 10 Nov 2013 22:04 But I saw AC solution in double without epsilon :) Re: TEST 22 Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 11 Nov 2013 00:08 If you're quite lucky or tests are weak - it is possible, but anyway quite risky on the real contest. | | Important test ! | Adhambek | 1794. Masterpieces of World Architecture | 10 Nov 2013 18:37 | 1 | 4 3 1 4 2 answer : 3 12 1 3 5 6 4 1 3 5 7 10 8 2 answer : 11 8 8 2 5 8 1 3 4 5 answer : 4 9 5 3 2 5 4 7 9 2 1 answer : 9 10 2 2 4 4 5 8 7 9 9 1 answer : 1 Edited by author 10.11.2013 18:43 | | Whats the test test#3 Im getting WA in this test, Help please. | CELO | 1031. Railway Tickets | 10 Nov 2013 14:24 | 2 | you should set distance of station 1 = 0, as input: distance from 1 to 2 = 2 | | HELP!!! TLE in #9 | garnett | 1156. Two Rounds | 10 Nov 2013 13:16 | 1 | | | wrong answer #3 | liujialin | 2003. Simple Magic | 10 Nov 2013 02:57 | 2 | 3 1 1 1 output is 0 and I ignored this condition. | | A question regarding the question..... | Jaideva | 1036. Lucky Tickets | 10 Nov 2013 01:06 | 1 | The value of N is <= 50, so we are talking about a 100 digit number atmost.....how then the upper limit of S is 1000.....shouldn't it be 900.....or are we supposed to return 0 when (2*N*9) < S. Am I missing something ????? Edited by author 10.11.2013 01:07 Nevermind.....I solved it..... Few useful insights :- (i) if S > (2*9*N) output 0; (ii) if S = 0 output 1; (otherwise you would get WA for test 5). Edited by author 10.11.2013 02:27 |
|
|