Common BoardThank you very much for the formula. I can prove it. But had not found it. Something very dark... The solution is more easy and more easy to understand too! I can prove it . but i don't know how did you come out with that? I can prove it . but i don't know how did you come out with that? It's simple. Just c=n^2 ( by intuition ). So, find a and b. a=n^2+c and b=n^2+d ( because n^2 <= a,b,c <= (n+1)^2 = n^2 + 2*n + 1 ), where c and d is positive and c!=d( because a!=b(by text of this problem ) ) a^2 + b^2 = (n^2+c)^2 + (n^2+d)^2 = 2*n^4 + 2*n^2(c+d) + c^2 + d^2 Look at this 2*n^4 + 2*n^2(c+d) + c^2 + d^2. Each summand must be divisible on c=n^2. So, just, c = n and d = 2*n Answer: a = n^2 + n b = n^2 + 2*n c = n^2 P.S.: You can say just a = n^2 and analogous prove another formula. Edited by author 03.12.2011 03:41i was very surprised it's just 3 strings of code you're perfect =) There is no direct hint in task description that first n/2 and last n/2 should sum up in n case instead of first 3 and last 3 digits. Wouldn't it be more correct to replace "the first 3 digits" with "the first half of digits"? Why crash tell me please? program My; var n,k,i,i2,en,j,count:longint; a,b:array [1..4000] of longint; block:array[1..3,1..4000]of longint; ready:boolean; begin en:=1; for i:=1 to 3 do begin readln(n); for i2:=1 to n do begin read(k); ready:=true; for j:=1 to en do begin if k=a[j] then begin ready:=false; if block[i,j]=0 then begin inc(b[j]); block[i,j]:=1; end; end; end; if ready = true then begin a[en]:=k; b[en]:=1; block[i,en]:=1; inc(en); end; end; end;
for i:=1 to en do begin if b[i]=3 then inc(count); end; writeln(count); end. Who gets WA#21 try this test: - IS IT CORRECT? - YES, IT IS. answer: - Is it correct? - Yes, it is. Edited by author 02.11.2008 21:33 Edited by author 02.11.2008 21:34 thanks! thank you very very mush:)))))))))))))))):)))))))))))))))))) i got ac in 14 line c++; 0.015s The input is of multiple testcases, and each testcase starts with N, the length of the sequence, and K, the number of pairs of intervals. You only know when you stop after got N == -1. Naive ideas will get TLE even for testcase #1, and you will see your code runs out of 2s limit when feeding a testcase with N=10^9 and K=5000, when all pairs are good and you should output 5000. My program 4729094 got AC, but the same program gives WA2 on problem 1593 (harder tests). So, there is a class of numbers those my solution gives incorrect answer and I think some of such numbers must be below 60000 2nd test of problem 1593 was added to the test set using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace timusPin { class Program { static void Main(string[] args) { int max; int e=0, m=0, l=0; max = int.Parse(Console.ReadLine()); string[] arr = new string[max]; for (int v = 0;v <= max -1 ;v++) { arr[Convert.ToInt32(v)] = (Console.ReadLine()); } for (int v = 0;v <= max -1 ;v++) { if (arr[v] == "Emperor Penguin") { e++; } if (arr[v] == "Macaroni Penguin") { m++; } if (arr[v] == "Little Penguin") { l++; } } if (e > m && e > l) { Console.WriteLine("Emperor Penguin"); } if (m > e && m > l) { Console.WriteLine("Macaroni Penguin"); } if (l > e && l > m) { Console.WriteLine("Macaroni Penguin"); } // Console.ReadKey(); } } } WHY Wrong Answer???? if (l > e && l > m) { Console.WriteLine("Little Penguin"); } Please add this test 2 1 10000 1 1 my program showed YES this test but Accepted \u002f\u002a public class Main {} \u002a\u002f \u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0069\u006f\u002e\u002a\u003b\u000d\u000a\u0069\u006d\u0070\u006f\u0072\u0074\u0020\u006a\u0061\u0076\u0061\u002e\u0075\u0074\u0069\u006c\u002e\u002a\u003b\u000d\u000a\u000d\u000a\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0063\u006c\u0061\u0073\u0073\u0020\u004d\u0061\u0069\u006e\u0020\u007b\u000d\u000a\u000d\u000a\u0009\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u0020\u0069\u006e\u003b\u000d\u000a\u0009\u0050\u0072\u0069\u006e\u0074\u0057\u0072\u0069\u0074\u0065\u0072\u0020\u006f\u0075\u0074\u003b\u000d\u000a\u0009\u000d\u000a\u0009\u0076\u006f\u0069\u0064\u0020\u0073\u006f\u006c\u0076\u0065\u0028\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0069\u006e\u0074\u0020\u0061\u0020\u003d\u0020\u0069\u006e\u002e\u006e\u0065\u0078\u0074\u0049\u006e\u0074\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u0069\u006e\u0074\u0020\u0062\u0020\u003d\u0020\u0069\u006e\u002e\u006e\u0065\u0078\u0074\u0049\u006e\u0074\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u006f\u0075\u0074\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0061\u0020\u002b\u0020\u0062\u0029\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u0009\u000d\u000a\u0009\u0076\u006f\u0069\u0064\u0020\u0072\u0075\u006e\u0028\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u0069\u006e\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0053\u0063\u0061\u006e\u006e\u0065\u0072\u0028\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u0069\u006e\u0029\u003b\u000d\u000a\u0009\u0009\u006f\u0075\u0074\u0020\u003d\u0020\u006e\u0065\u0077\u0020\u0050\u0072\u0069\u006e\u0074\u0057\u0072\u0069\u0074\u0065\u0072\u0028\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074\u0029\u003b\u000d\u000a\u0009\u0009\u0074\u0072\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u0073\u006f\u006c\u0076\u0065\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u0020\u0066\u0069\u006e\u0061\u006c\u006c\u0079\u0020\u007b\u000d\u000a\u0009\u0009\u0009\u006f\u0075\u0074\u002e\u0063\u006c\u006f\u0073\u0065\u0028\u0029\u003b\u000d\u000a\u0009\u0009\u007d\u000d\u000a\u0009\u007d\u000d\u000a\u000d\u000a\u0009\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0073\u0074\u0061\u0074\u0069\u0063\u0020\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028\u0053\u0074\u0072\u0069\u006e\u0067\u0020\u0061\u0072\u0067\u0073\u005b\u005d\u0029\u0020\u007b\u000d\u000a\u0009\u0009\u006e\u0065\u0077\u0020\u004d\u0061\u0069\u006e\u0028\u0029\u002e\u0072\u0075\u006e\u0028\u0029\u003b\u000d\u000a\u0009\u007d\u000d\u000a\u007d Could you please check my submissions. The accepted one (I actually copy-pasted it from this forum) gives wrong answer to the following data set: tram (only 4 symbols in input.txt file) The output is "Bus driver". My original solution (#4725054) gives "Tram driver" answer to the mentioned data set, but fails on test #6. Can you please give information what is wrong with this test? Thank you. Last line of input data is always terminated with end of line character (it is the usual rule of Timus Online Judge), so this test is incorrect. Ok, got this. So I assume the problem is on my side. Will try to find what is wrong Just use diagonal painting: 1 2 3 ... k ... (total n times) 2 3 4 ... 1 ... (total n times) . . . ... . ... (total n times) Calculate, how many 1,2, ... k in this table. Answer will be minimal of them(every rectangle 1xK covers K different colors). I don't no is this mathematically correct, but this solution got AC. Don't forget, that if N < K answer is 0. P.S. Sorry for bad English. > Just use diagonal painting: > 1 2 3 ... k ... (total n times) > 2 3 4 ... 1 ... (total n times) > . . . ... . ... (total n times) > Calculate, how many 1,2, ... k in this table. Answer will be minimal > of them(every rectangle 1xK covers K different colors). > I don't no is this mathematically correct, but this solution got AC. > Don't forget, that if N < K answer is 0. > P.S. Sorry for bad English. email me: caa@baga.ac.net.ru >>> vasilisk_voin@mailru.com Can anybody give me example for this table?Please... For example what table will be if n=5 k=3 ? if N=5 and K=3 the correct answer is 8 but not 7. To see the solution don't use the square (3,3) in the 5*5 grid Edited by author 13.11.2005 13:39 Edited by author 13.11.2005 13:39 Why such found minimal value really achivable in all cases? its because for each number in the table there you can put 1*K piece so that it won't intersect with others.And answer is minimum value because each piece lays on K diffirent numbers so you can't put more pieces that numimum value of 1...k PS. Thanks! It's really easy to solve with O(1) time with your tips! This is only your belive... Told property has only minimal number. THE PROOF 1) if you "stack" the coffins, you use up all of the graveyard, except for N%K square in the corder. 2) if you "spiral" the coffins, you leave N-2(N%K) square in the middle after the first spiral, N-4(N%K) square after the second spiral, until you use up all of the graveyard, except for (N-2(N%K))%K square in the middle. (N-2(N%K))%K = (-N)%K = K-N%K 3) if we use the better of the two strategies, we use up all of the graveyard, except for M=min(N%K, K-N%K) square. How many colors will it have? The first row will be colored 1..M, the second 2..M+1, the last M..2M-1 All K colors will be present iff 2M-1>=K 4) M=min(N%K, K-N%K) guarantees M<=K/2 Therefore, the remaining square will not have all K colors. This proves that using the better of the two strategies exhausts at least one of the K colors, QED. please tell your idea more in detail thanks, i got AC when i use your idea. but i dont why it's true? who's know?
Can you generate me some tests with answers? I'd like to check my program. Put R+,Q+. Try this: 1000000 1000000 1000000 1000000 1 1000000 1000000 999999 1000000 3 1000000 0 1 1000000 2 I think that answer on the last test must be 3. (1+1000000i)*(-i)+i=1000000 (1+1000000i)*(1-i)-1-999999i=1000000 (1+1000000i)*0+1000000=1000000 Some random tests: 21 56 32 45 3 90 87 45 23 4 234 876 129 623 2 12345 65 8967 1345 3 4563 897 156 734 4 4 6 7 8 3 4 3 3 1 2 4 2 2 3 2 3 4 3 27 1 0 15 4 0 45 4 0 my solutin gives "4 4". But still WA#15 my solution also gives "4 4". But still WA#15, what can i do? Hi, guys! In the problem statement input is a string, that consists of a..z or A..Z. Let me guess, Test 7 has some other chars ? If so, please, correct prom statement with this note. 4 my submissions were with WA#7 until I added char check Test 7 consists of characters a..z and A..Z only. I had the same situation as topic starter. Maybe there is '\n' at the end of the test #7. #include<cstdio> #include<string.h> #include<algorithm> using namespace std; const int M1 = 555; const int INF = 111111111; int N,K; int ans; int w[M1][M1];//w[i][j] is the number of white horses in the last stable when the first i horses were placed in 1st j stables with minimum unhappiness int b[M1][M1];//b[i][j] is the number of black horses in the last stable when the first i horses were placed in 1st j stables with minimum unhappiness int f[M1][M1];//f[i][j] means the minimum unhappiness when the first i horses were placed in 1st j stables //function: f[i][j] = min(f[i-1][j-1],f[i-1][j]+w[i-1][j] or b[i-1][j]); int main() { memset(w,0,sizeof(w)); memset(b,0,sizeof(b)); memset(f,0,sizeof(f)); scanf("%d%d",&N,&K); for(int i=0;i!=M1;++i) { for(int j=i+1;j!=M1;++j) f[i][j] = INF; f[i][0] = INF; } int tmp; scanf("%d",&tmp); if(tmp) ++b[1][1]; else ++w[1][1]; f[1][1] = 0; for(int i=2;i<=N;++i) { scanf("%d",&tmp); for(int j=1;j<=min(i,K);++j) { f[i][j] = f[i-1][j-1]; b[i][j] = 0; w[i][j] = 0; if(tmp) { ++b[i][j]; if(f[i-1][j]+w[i-1][j]<f[i][j]) { b[i][j] = b[i-1][j]+1; w[i][j] = w[i-1][j]; f[i][j] = f[i-1][j]+w[i-1][j]; } } else { ++w[i][j]; if(f[i-1][j]+b[i-1][j]<f[i][j]) { b[i][j] = b[i-1][j]; w[i][j] = w[i-1][j]+1; f[i][j] = f[i-1][j]+b[i-1][j]; } } } } ans = f[N][K]; printf("%d",ans); return 0; } I think I have precision problems, please inspect my code (CSharp) and give some hints: UPD: ok, I found some mistakes in my algorithm. Edited by author 08.01.2013 14:49 OK, I got AC, but I have question to admins: Is there test with n = 1000, m = 1000? My solution on my PC works more than 0.5 secs with such test. try to solve this with dp. my solution with dp( O(n*m) ) works on my pc only 0m0.016s if n=m=1000 :) |
|