Common BoardIf you got TLE, try change adjacency matrix to edge list. Bitset<30> operation "|" helps to avoid inner N-loop = 、=  Using edge list, got TLE. I got AC changed edge list to adjacency matrix. Did you use DP to solve this problem? How did you do it? use greedy algo instead. choose the largest numbers for the innermost square roots so that their values get depreciated with each iteration. this is how i did. sort arr in reverse order   [code deleted]   cur is the final answer   Edited by moderator 19.10.2019 19:45 you can use dp in this task, like in the classical task "how to multiply n matrices in optimal way". it's O(n^3), so suitable.   also there's greddy algorithm, O(n). 1 1 2 1   1 2 3 2   234 532 245 3   12345 87654 23456 4   1223456 8098887645 567321 4   12345 654345678 1234567890 5   Edited by author 05.07.2011 20:09 Hey Maria, Problem states that the input, consists of 3 space-separated pairwise DISTINCT integers so your first example doesn't satisfy conditions and hence, is useless.   Regards, Sepehr 99 8 1 3 thanks :) got AC after testing you input and fixing the program P.S. long in JAVA is enough!!!! Maria , for test number 4, I think the answer should be 3 : First aborigine brings a pile of 75309 ( 87654-12345 ) , the second aborigine also brings a pile of 75309 stones , because that's still the biggest difference , and the third points to the two equal piles. Correct me if I'm wrong! hopless dreamer, No, u r wrong. The FIRST aborigine will bring the pile of 64198 stones, becouse it's the LEAST. And the second aborigine will bring the pile of 64198 - 23456 = 40742 stones and so on. "Professor asked one of the aborigines to point at two piles with the MINIMAL difference of numbers of stones in them and tell what this difference is."   Edited by author 06.07.2012 18:07   Edited by author 06.07.2012 18:07 -1000 0 0 1 1 the real output is 0. 1000 1 0 2 1 the answer  4.34665576869374564E+0208  1000 1 0 2 1  the answer   4.34665576869374564E+0208
   1000 1 0 2 1  the answer   4.34665576869374564E+0208
   the real answer is -1  -1000 0 0 1 1  the real answer is 2 1000 1 0 2 1 the answer  -1 wrong see 0 1  2 3 4 5 6 7 ... 1000 2 -1 1 0 1 1 2 3 ... big integer value   i think  it is incorrect test, all value integer(..sequence of integer numbers...) What is on 18 test? Why do you think it is "almost solved"? A problem may have arbitrary number of tests (sometimes 200+), so WA #18 doesn't mean "almost solved", it means "not solved". for n = 10000 and m = 100000 you get approximately 2.10^6. the only way to get 0.79 is if the constant is big enough. mine is O(m + n) and I get 0.079 my algo O(m+n) too, 0.046 s O(m+n^2) algo gets AC with 0.046 :D thanks a lot. I really didn't know what to do with test 13 Cockroaches!蟑螂 Time Limit: 1 second Memory Limit: 1000K     It's well-known that the most tenacious of life species on the Earth are cockroaches. They live everywhere if only there in food. And as far as they are unpretentious in food you can find them absolutely everywhere. 众所周知地球上最顽强的生命种类是蟑螂,他们生活在有食物的任何地方。只要有食物,你就可以发现他们的影踪。   A little Lyosha studies at school on a Space station. During one of the school competitions his class has reached the final. A task of the final contest is to exterminate all the cockroaches in the cargo module within minimal time. Lyosha 在太空站的学校学习。在学校的一项竞赛里,他们班已经到达接近尾声,其中一项任务是在最小的时间里消灭货物仓里的蟑螂。   Within the long history of the competitions a unified tactics was worked out. The tactics is as follows: a poison gas is let in one of the module compartments and after that the baffle that separates the compartment from one of the adjacent ones is opened.  Cockroaches can't stand the smell of the gas and run to the other compartment. When there's no cockroaches in the treated compartment the baffle is closed. Afterwards analogously the next compartment is treated, and so on. The goal is to move all the cockroaches to the floodgate of the cargo module. Then the outward door is opened and all the cockroaches are engulfed by an open Space. 他们在长时间的竞赛里,已经形成了统一的战术。 战术是这样的:把毒气放在一个厢房里,另外,打开闸门(隔开相邻厢房的门)。蟑螂不能忍受毒气的味道,会纷纷逃向隔壁的已打开的厢房,如此下去。目标是把所有的蟑螂赶向floodgate货物仓(的闸门)。   Lyosha is responsible for programming the control board of the baffles in his team. The baffles are opened slowly, so it's very important to make do with minimal number of baffle openings in order to win in the contest. Your task is to help Lyosha to compute this number. Lyosha负责闸门的规划控制,闸门开得慢,所以这项工作对于竞赛的胜负是很重要的,要设法使到开最少的门。你的任务是帮助Lyosha 计算这个数。   Input The first line contains a name of the floodgate compartment. Each of the next lines contains description of one of the baffles - the names of two compartments separated with a dash (-). The last line contains the only symbol "#". There are cockroaches in all the compartments of the module at first. It's possible to get to the floodgate from every compartment of the module passing several baffles. The total number of compartments doesn't exceed 30. The name of a compartment consists of no more than 20 Latin letters and digits. The large and the small letters should be distinguished. 首行为floodgate厢房名。以下每一行为两个厢房间的闸门名,两个厢房间用(-)隔开。最后一行只有“#”结束。开始时每个厢房都有蟑螂。每个厢房的蟑螂经过几个闸门后都能到达floodgate。厢房的数量不超过30个。厢房名不超过20个字母数字,区分大小写。   Output Your program is to output the only number - the minimal amount of baffles that should be opened (and then closed) in order to move all the cockroaches to the floodgate. 输出最小的数字,即为了能把蟑螂赶到指定的floodgate,要开的门数 (当然开完后又关上)   Sample Input Gateway Machinery-Gateway Machinery-Control Control-Central Control-Engine Central-Engine Storage-Gateway Storage-Waste Central-Waste # Sample Output 6   thx anyway for translating it to Chinese Thank, I have Got WA13) now AC I just want to know why the answer is Number_comparments - 1 Because you can make a tree from comparments and then open the baffles from the leaves to the root of tree using only n-1 baffle. если число четное то его можно представить как сумму двух  простых чисел, а если оно нечетно то либо как сумму 2 простых либо как 3 + (a + b), a, b - простые, как определить для нечетного числа надо 3 или 2 числа --- if the number is even then it can be written as the sum of two primes, and if it is odd then either as the sum of two simple or as 3 + (a + b), a, b - prime.  How to determine the odd numbers must be 3 or 2 numbers? The sum of 2 odd numbers is always an odd number.   To have 2 numbers sum up to an odd number, one needs an even number and an odd number. In this case, 2 + (n-2) (because 2 is the only even prime).   Now, I'm stuck on how to solve the problem fast for even numbers #include <iostream> using namespace std;   int main() {     int a,b,c;     cin >> a;     b=a-1;     c=a+1;     if (a%10+(a/10)%10+(a/100)%10==(a/1000)%10+(a/10000)%10+(a/100000)%10 || b%10+(b/10)%10+(b/100)%10==(b/1000)%10+(b/10000)%10+(b/100000)%10 || c%10+(c/10)%10+(c/100)%10==(c/1000)%10+(c/10000)%10+(c/100000)%10)         cout << "YES";     else     {         cout << "NO";     }     return 0; } I used Floyd and get WA 4. I use BFS, but I get WA 4. :(   Why? What is the special effect? What features at our tram routes? YAHOO!!! I got AC.   if you get WA4 -> travel card = unlimit if you get WA6 -> test when answer = 0 the e-mail id with which i have registered as an acm member is going to be deactivated,as it was given by the college.Is their any problem regarding that?what should i do? Причем все эти посылки Accepted, так что это явно лишено смысла. Пожалуйста, сделайте с этим что-нибудь. Или такое заспамливание очереди никак не запрещается?   Upd. Кажется, посылки прекратились.   Edited by author 16.12.2013 17:13 Dear moderator or anybody else,   Could you please give me testcase 10,I got WA on it,Thanks so so much   Edited by author 03.11.2007 14:35   Edited by author 03.11.2007 14:35 I wa on test 10 many times too. thx First,maxn=100,and I wa on test10 eleven times. After that,maxn=200------>got AC!My god! yeah, I've made the same mistake. Thanks! my algo incorrect?   Edited by author 01.11.2009 16:45 Pirated is  Licensed to Pirated  Pirated to Pirated   Licensed is  Licensed to Licensed   Cracked is  Pirated to Pirated  Licensed to Licensed Cracked is  Pirated to Pirated  Licensed to Licensed It means that programm became Cracked, if we have Pirated version and then we install Pirated OR if we have Licensed version and then we install Licensed version?   Pirated is Licensed to Pirated Pirated to Pirated   Licensed is Licensed to Licensed   Cracked is Pirated to Pirated Licensed to Licensed Are you sure, that it is enough? What about if we install Cracked version after any of other versions?  Edited by author 02.11.2009 15:52To everyone. If you have WA#10 read the problem state carefully. A pirated program can never become licensed again. import java.util.*; import java.io.*; public class p1001 {     public static void main(String[] args) throws Exception {         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));         ArrayList<String> nums = new ArrayList<String>();         String line;         while (true) {             line = br.readLine();             if (line == null) break;             StringTokenizer st = new StringTokenizer(line);             while (st.hasMoreTokens()) {                 nums.add(st.nextToken());             }         }
          for (int i = nums.size() - 1; i >= 0; i--) {             int num = Integer.parseInt(nums.get(i));             System.out.printf("%.4f\n", Math.sqrt(num));         }     } } you did not account for the max size limit on the input.... tl;dr And only one guy could solve this :D Each sentence in problem statement makes sense, it can't be reduced. There are three author solutions, but two other guys didn't submit them. BTW, I don't think that this problem so difficult, try to solve it.   P.S. "Условие задачи" = "Problem statement", "condition" - условие, которое может быть истинным или ложным   Edited by author 14.12.2013 18:41 Hey, guys, i've did it! No need to be so smarty, just use long long :) Formula is obvious and it already somewhere in this forum, so you can find it   USE LONG LONG!  |  
  |