Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Why my code get TL? | Felix_Mate | 1386. Maze | 4 Jan 2017 23:10 | 1 | There is about nmax*nmax*smax=40 844 804 iterations and time must be about 0.1,0.2 sec. But program works >0.5 sec. How I can to optimize my code? const nmax=101; kmax=4; smax=4004; type myint=0..smax+1; var ans:array[1..nmax,1..nmax] of boolean; count,s,t:myint; n,m,i,j,k,x,y,ii,jj:myint; command:array[1..nmax,1..nmax,1..kmax,1..2] of byte; memory:array[1..nmax,1..nmax,1..smax] of boolean; list:array[1..smax] of byte;
begin readln(n,m);
for k:=1 to kmax do begin for i:=1 to n do begin for j:=1 to m do read(command[i,j,k,1],command[i,j,k,2]); end; end;
read(s); for i:=1 to s do read(list[i]);
for t:=1 to s do begin for i:=1 to n do begin for j:=1 to m do memory[i,j,t]:=false; end; end;
count:=0; for i:=1 to n do begin for j:=1 to m do begin ans[i,j]:=false; end; end;
for i:=1 to n do begin for j:=1 to m do begin t:=1; ii:=i; jj:=j; while(t<=s)and(not memory[ii,jj,t]) do begin memory[ii,jj,t]:=true; x:=command[ii,jj,list[t],1]; y:=command[ii,jj,list[t],2]; ii:=x; jj:=y; inc(t); end; if(t>s)and(not ans[ii,jj]) then begin inc(count); ans[ii,jj]:=true; end; end; end;
writeln(count); for i:=1 to n do begin for j:=1 to m do begin if(ans[i,j]) then writeln(i,' ',j); end; end; end. Edited by author 04.01.2017 23:24 Now AC. When I used a lot of memory, I got TL32. When I used a little memory, I got AC.Perhaps the cache helped. Edited by author 23.06.2017 19:24 | | WA 4 | Lev_Kireenko 🐬 | 1728. Curse on Team.GOV | 4 Jan 2017 16:12 | 1 | WA 4 Lev_Kireenko 🐬 4 Jan 2017 16:12 Why WA4 ??? give me some test please | | WA9 please help | genchildren | 1118. Nontrivial Numbers | 4 Jan 2017 13:48 | 2 | #include <iostream> using namespace std; bool prime(long long n); int main() { long long a,odd, i, j, nice,b; cin >> a >> b; nice=0; if (a%2==1) {odd=a;} else {odd=a+1;} for (i=b; i>a; i--) { if (prime(i)) { nice=i; break; } } if ((a==1 or nice==0) and b!=a) { cout << odd;} else if (b==a) {cout << a;} else if (nice) {cout << nice << endl;} return 0; } bool prime(long long n) { bool w; w=n==2; if (!w and n%2) { w=1; for (int i=3; i*i<=n; i+=2) { if (n%i==0) { w=0 ; break; } } } if (w) { return 1; } else return 0; } Case "no prime is found" is suspicious. You think answer is the minimal odd number in the interval. Could you prove it? Why not maximal odd number in the interval? Why you don't want to do try brute force? | | I get WA#3.What is the right answer for this tests? | Enigma [UB of TUIT] | 1036. Lucky Tickets | 3 Jan 2017 23:51 | 5 | In: 2 4 Out: 9 In: 2 6 Out: 16 In: 2 8 Out: 25 In: 4 2 Out: 16 In: 4 4 Out:100 In: 4 6 Out: 400 In: 4 8 Out: 1225 :) As far as I guess, the right answer for WA3 is zero. And it comes up when, for instance, you have "N=2" and "S=38". Four bits cannot produce the sum more then thirty six, you know. My answers are same for all the test cases you have written here. My recursive formula is m[len][sum] = m[len-1][sum-k] for 0<=k<=9. Then why is it showing wrong anwser for test case 2. Edited by moderator 12.01.2022 16:54 answer is very big it cannot be stored in 64 bits , U need to find another way. | | Don't know the wrong | Mukul Barai | 1002. Phone Numbers | 3 Jan 2017 21:31 | 2 | Please somebody help me. I can not find the reason not to be accepted my code. #include <iostream> #include <string> #include <vector> using namespace std; bool found; string convert(string str) { string char_list = "22233344115566070778889990"; string to_digit; for(int i=0; i<str.length(); i++) { to_digit += char_list[str[i]-97]; } return to_digit; } void dfs(vector<int> index[], vector<int> ends[], string diction[], vector<int> track, int i, int n) { if(found == true) { return; } if(i == n){ for(int j=0; j<track.size(); j++) { cout<<diction[track[j]]<<" "; } found = true; return; } for(int k=0; k<ends[i].size(); k++){ track.push_back(index[i][k]); dfs(index, ends, diction, track, ends[i][k], n); track.pop_back(); } } int main() { for(; ;){ found = false; string number; cin>>number; if(number == "-1"){ break; } int dic_size; cin>>dic_size; string diction[dic_size]; for(int i=0; i<dic_size; i++){ cin>>diction[i]; } int n = number.size(); vector<int> ends[n]; vector<int> index[n]; for(int j=0; j<dic_size; j++) { string str = convert(diction[j]); int len = diction[j].size(); for(int i=0; i<n; i++) { if(number.substr(i,len) == str){ ends[i].push_back(i+len); index[i].push_back(j); } } } vector<int> track; dfs(index, ends, diction, track, 0, n); if(found == false){ cout<<"No solution."; } } return 0; } Edited by author 03.01.2017 20:24 Have you tried to compile it? cin>>dic_size; string diction[dic_size]; vector<int> ends[n]; ends[i].push_back(i+len); It would be great if you post link to ideone.com (for example) run. Run should contain expected task example output. Edited by author 03.01.2017 21:35 | | What is complexy? | Felix_Mate | 1487. Chinese Football | 3 Jan 2017 13:32 | 1 | My algo is O(N*N*sqrt(N)). | | please tell me, what's wrong? | Victoriya | 1211. Collective Guarantee | 3 Jan 2017 01:40 | 1 | var g:array[1..25000,1..25000] of integer; v,i,j,n,f,un,uk,t,k,s,x:longint; Q:array[1..100000] of integer; p:array[1..25000] of integer; begin assign(input,'input.txt'); assign(output,'output.txt'); reset(input);rewrite(output); readln(t); for i:=1 to t do begin readln(n);k:=0; fillchar(g,sizeof(g),0); for j:=1 to n do begin read(s); if s=0 then begin f:=j; k:=k+1;g[j,j]:=0;end else begin g[j,s]:=1;g[s,j]:=1;end; if k>1 then break; end; readln; if k<>1 then begin Writeln('NO');end else begin for j:=1 to n do p[j]:=-1; fillchar(Q,sizeof(Q),0); un:=1; uk:=2; Q[1]:=f; p[f]:=0; x:=0; while un<>uk do begin v:=Q[un]; un:=un+1; for j:=1 to n do if (g[v,j]<>0) and (p[j]=-1) then begin Q[uk]:=j; uk:=uk+1; p[j]:=p[v]+1; end; end; for j:=1 to n do if p[j]=-1 then begin x:=1;break;end; if x=0 then writeln('YES') else writeln('NO'); end; end; end. | | WA 11 | NumbMoon | 1795. Husband in a Shop | 2 Jan 2017 23:52 | 1 | WA 11 NumbMoon 2 Jan 2017 23:52 Could anyone give me some tests for this one? | | I cant understand the problems!!!! | Xudong_LI | 1092. Transversal | 2 Jan 2017 23:36 | 2 | Could someone tell me what's the meaning of this problem?my english is noot good.The google translation is bad. let: 2D array[N][N], and transversal is a cells of N , which for each row and each column has one cell in the transversal. for example: 2D array: 1) 2) 3) ============= 1)| 1 2 3 2)| 4 5 6 3)| 7 8 9 transversal-1: { (1;1) , (2;2) , (3;3) } // (row, col) -- coordinate of a cell, . transversal-2: { (1;1) , (2;3) , (3;2) } transversal-3: { (1;2) , (2;1) , (3;3) } transversal-4: { (1;2) , (2;3) , (3;1) } transversal-5: { (1;3) , (2;1) , (3;2) } transversal-6: { (1;3) , (2;2) , (3;1) } Note that, there 1*2*3...*N = N! different transversals exist. Now, about problem: 2D array with 2N+1 x 2N+1 size , elements '+' or '-'. And allowed operation: can change sign to opposite in all cells in a transversal. You are asked to determine if it is possible to obtain a table containing not more than 2N cells with the sign "+" by a sequence of such operations Good Luck!
| | Algorithm ! AC 0.031 | Phan Hoài Nam (HUFLIT) | 1097. Square Country 2 | 2 Jan 2017 23:12 | 4 | Split your land and get smaller lands ! First, you have a land (1,1)(n,n) For example: Your land: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 after adding the land with maximal importance: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 9 1 1 1 1 9 9 1 1 1 1 1 1 1 1 1 1 1 1 1 1 You have 4 new lands: 2 lands: a a a a a a a a a a a a 1 1 9 9 1 1 1 1 9 9 1 1 a a a a a a a a a a a a and 2 lands: a a 1 1 a a a a 1 1 a a a a 9 9 a a a a 9 9 a a a a 1 1 a a a a 1 1 a a For each of your new lands, you continue add other lands with decreasing importance. Finally, you will find out that after adding a land with a certain importance t, you can't create a land with desired park size. Now, you end your program and output t. THE END ^^! Edited by author 08.10.2010 14:39 Edited by author 12.10.2010 10:14 Hmmm.... I've tried this strategy using BFS and got ML3. Using recursion TL3. So probably i'm missing something. here is pseudo code for my recursive solution int findMin(List<Rectangle> lands, Rectangle area, int startFrom) { if (minSide(area) < regionSize) return startFrom - 1; Rectangle land = firstLandThatIntersectsArea(lands, area, startFrom); if (land == null) return 1; findMin(lands, top(area, land), indexOf(land) + 1); findMin(lands, right(area, land), indexOf(land) + 1); findMin(lands, bottom(area, land), indexOf(land) + 1); findMin(lands, left(area, land), indexOf(land) + 1); } call findMin(sortedDescByPriority(lands), new Rectangle(1, 1, n, n), 0); Send me the code, please! goldenxbullet@gmail.com Thanks! Algorithm! AC 0.001 1. use buffered i/o. 2. check only on row = build_row + build_side, and col = build_col + build_side coordinates. its very simple. More formal: let build structure: struct build{ int priority; int len; int row; int col; } build d[M]; int L, A; // L - length of square city, A - length of building Park . so need to check only (think about it!!!) row = d[i].row + d[i].len ; col = d[j].col + d[j].len ; i=0..M-1,j=0..M-1 coordinates. Good Luck!!! Don't forget also, for row + A-1 <= L and col + A - 1 <= L | | yet another hint WA12 | c_pp | 1074. Very Short Problem | 2 Jan 2017 21:28 | 1 | in more languages "3." or "0.E+6" numbers are legal. but for there are not, i.e. input: 3. 1 0.E6 3 # output: Not a floating point number Not a floating point number Edited by author 02.01.2017 21:42 | | Runtime error test 9 | NumbMoon | 1795. Husband in a Shop | 2 Jan 2017 21:14 | 1 | Could someone give me some tests for this one? | | If you have WA 3 | Moonstone [Samara SAU] | 1795. Husband in a Shop | 2 Jan 2017 21:09 | 5 | Try this test case: 1 1 of vodka 1 2 of vodka Answer = 1 Thank you! I was being mad about this WA during the contest. :) Why answer is 1? He wants more than is in the shop, so he calls his wife and asks her. This means that the answer is 2. Or I misunderstood? Because he is letting our hero go in front of him, which is the main objective. | | Can't figure out the "swap" part | NumbMoon | 1795. Husband in a Shop | 2 Jan 2017 18:20 | 1 | Could anyone, please, explain it to me? I can't understand how to program it. I'm filling the "amount of name" for the storage in the shop and for the queue, then, for each human from the queue, I check, firstly, whether the shop has the product the customer needs to buy, and then, if the shop has it, I compare the amounts. But I have a problem in understanding the part where the shop doesn't have enough of the product and the customers switch places. Could anyone explain it to me? | | What is Test 2? | Daniel Paleyev SESC USU | 2035. Another Dress Rehearsal | 1 Jan 2017 23:46 | 2 | | | Wrong answer... help me.. plz | Vonni | 1224. Spiral | 1 Jan 2017 23:45 | 3 | #include <stdio.h> int main() { int N, M; scanf("%d%d",&N,&M); long int res; if (N <= M) res = 2 * (N - 1); else res= 2 * (M - 1)+1; printf("\n%d",res); return 0; } Can't solve this promlem myself. I run your code online on some tests, it seemed ok. Check, maybe you go out of range in res? (know nothing about C) | | why this is not accepted? | Md.Toufiqul Islam | 1000. A+B Problem | 31 Dec 2016 14:43 | 4 | where is the problem #include<stdio.h> int main(void) { int a,b,sum; printf("a:"); scanf("%d",a); printf("b:"); scanf("%d",&b); sum=a+b; printf("Sum=%d",sum); return 0; } Edited by author 03.12.2015 01:58 And. Did you run it locally? Try please. You should have crash here: scanf("%d",a); scanf("%d",a); scanf("%d",&a); | | can someone help me? | Alexandar | 1386. Maze | 30 Dec 2016 15:00 | 11 | I really can't solve this task? Alwaus got TLE on test 39 :-( Can someone give me hint or ... As for me, simpliest way is to use assembler instructions. There are some optimizations like this: Bad code: for (x = 0; x < W; x++) for (y = 0; y < H; y++) A[y][x] = 1; This code works much faster than previous one: for (y = 0; y < H; y++) for (x = 0; x < W; x++) A[y][x] = 1; Still nothing :-( This problem is driving me crazy!!!! There is one optimization, that speeds up simple solution in about 5 times. So, keep on solving. Please send me some hint!! a:array[1..4,1..10000] of word; for k:=1 to 4 do for i:=1 to n*m do begin if i mod m=0 then readln(p1,p2) else read(p1,p2); a[k,i]:=(p1-1)*m+p2; end; this be fast i think it more faster :) a:array[1..4,101..10100] of word; for k:=1 to 4 do for i:=1 to n*m do begin if i mod m=0 then readln(p1,p2) else read(p1,p2); a[k,i]:=p1*m+p2; end; Вообще если про скорость проверка if i mod m=0 все тормозит k++; if (k==m){ readln(p1,p2); k=0; } else read(p1,p2); надо так и еще очень ускоряет (покрайней мере у меня разные там битовые сдвиги) I wrote a starightforward O(N*M*S) solution without any optimizations and got AC. Had TLE in java. Rewritten in C -> AC. | | Hint test 9 | Cebotari Vladislav | 1562. GM-pineapple | 30 Dec 2016 14:59 | 1 | I had a program like that: while (x <= b/2) { .... x += dx } but it will fail test 1 1 100 (the last piece won't show). Changed to while (x <= b/2 + 0.000001) { .... x += dx } Got AC! | | Faster Ideas | georgi_georgiev | 1071. Nikifor 2 | 30 Dec 2016 00:39 | 4 | I Solved this problem, by transforming x and y into every system and search for the longest common substring. But I am interested in another Ideas, better than mine, except brute force. it isn't necessary to search LCS (O(|x|*|y|)), you can check only what y is subsequence of x, so it will be O(|x|+|y|) Edited by author 30.08.2009 16:00 Verification of this fact is O(log(max(x,y))) base = 2..1000 bruteforce, base > 1000 think a little :)) |
|
|