Common BoardНе слушайте тех кто пишет что убрал проверку за границы и зашла и все в таком духе. Возможно у вас такая же ошибка как и у меня, а то есть когда ввели новые координаты я проверял только то что может ли эту новую координату кто то ударить, а надо было еще проверить что может ли новая координа ударить кого то из врагов I use some shamanism ang get AC. Lets see to the next test: 6 0 20 10 50 30 100 60 120 70 130 110 140 my AC prog outputs: 2 10 50 110 140 but right answer of course is: 3 0 20 30 100 110 140 Your tests must be stronger Your test is added. Problem will be rejudged soon. test 6 0 -20 -10 -50 -30 -100 -60 -120 -70 -130 -110 -140 my AC solution have answer 2 -140 -110 -50 -10 on this test, so you've fucked up twice You have fucked up three times with wrong test my answer is : 10 50 60 120 70 130 this problem is quite easy but output is difficult to suitable to right answer !!!!! perhaps i get WA because of it Edited by author 15.03.2009 12:34 Thanks For the test~ I wa#12 and the test helped me. Edited by author 26.11.2009 08:19 Извините, что по-русски, надеюсь, администраторы знают этот язык. В условии сказано, что длина последовательности задается в первой строке каждого теста. В примерах на форуме длина общая для всех, в каждом тесте задается только количество вопросов. Моя AC-программа действует по форуму: читает длину один раз, а потом только количество вопросов для каждого теста. Хорошо бы привести текст задачи в соответствие с реальностью. Совсем хорошо было бы дать в примере два теста, чтобы сделать структуру входных данных действительно ясной. def word_to_num(word): d= {'a':'2','b':'2','c':'2','d':'3','e':'3','f':'3','g':'4','h':'4','i':'1','j':'1','k':'5','l':'5','m':'6','n':'6','o':'0','p':'7','q':'0','r':'7','s':'7','t':'8','u':'8','v':'8','w':'9','x':'9','y':'9','z':'0'} s='' for i in word: s+=d[i] return s from itertools import permutations while True: num_dict={} num_list=[] word_list=[] num = input() if num=='-1': break loop_len = int(input()) for i in range(loop_len): word_list.append(input()) for item in word_list: num_dict[word_to_num(item)]=item num_list.append(word_to_num(item)) perm = permutations(num_list,2) x=0 for k,v in list(perm): if k+v==num: print(num_dict[k]+' '+num_dict[v]) else: x += 1
if x==loop_len*(loop_len-1): print('No solution')
For Time limit exceeded: If you get time limit exceeded, it must mean that you're trying to modify the input string (i.e. trying to delete i-th chars). Try creating a new OUTPUT string without modifying the INPUT string. Note: if you're using a high language such as java or C#, try using the StringBuilder object to build your output string. For Wrong Answer(WA): If you get WA, try some of these test cases: Input: "dddd" Output: "" Input: "ddddd" Output: "d" Input: "abba" Output: "" Input: "abbbbac" Output: "c" Input: "wliisddsmmleeddw" Output: "" Input: "avcbbffcv" Output: "a" Hope this helps. Edited by author 12.07.2012 00:47 Input: "abbbbac" Output: "c" Спасибо, помогло! For Time limit exceeded: If you get time limit exceeded, it must mean that you're trying to modify the input string (i.e. trying to delete i-th chars). Try creating a new OUTPUT string without modifying the INPUT string. Note: if you're using a high language such as java or C#, try using the StringBuilder object to build your output string. For Wrong Answer(WA): If you get WA, try some of these test cases: Input: "dddd" Output: "" Input: "ddddd" Output: "d" Input: "abba" Output: "" Input: "abbbbac" Output: "c" Input: "wliisddsmmleeddw" Output: "" Input: "avcbbffcv" Output: "a" Hope this helps. Edited by author 12.07.2012 00:47 Thanks a lot...I could'n understand the problem statement first, now, reading ur comment I clearly understood the problem. for me problem was that program was returning "axx" on "aaaxx" Edited by author 18.03.2017 19:56 Hi, I writed this post because I wanted to share with you some of the test cases* that helped me a lot at the time. I hope it helps you :) --> Test 1: 1 A B C --> Answer: A undefined B undefined C undefined ------------------------------ --> Test 2: 5 Isenbaev A B A B C D Q P C H N G N P --> Answer: A 1 B 1 C 2 D 5 G 4 H 3 Isenbaev 0 N 3 P 4 Q 5 ------------------------------ --> Test 3: 13 Fominykh Isenbaev BBB BBB CCC AAA Ayzenshteyn Oparin Samsonov Ayzenshteyn Chevdar Samsonov Dublennykh Fominykh Ivankov Burmistrov Dublennykh Kurpilyanskiy Cormen Leiserson Rivest Oparin AA AAA Isenbaev Oparin Toropov AA DD PP PP QQ RR RR SS TT TT Toropov Oparin --> Answer: AA 2 AAA 2 Ayzenshteyn 2 BBB 1 Burmistrov 3 CCC 2 Chevdar 3 Cormen undefined DD 3 Dublennykh 2 Fominykh 1 Isenbaev 0 Ivankov 2 Kurpilyanskiy 3 Leiserson undefined Oparin 1 PP 3 QQ 4 RR 3 Rivest undefined SS 3 Samsonov 2 TT 2 Toropov 1 ------------------------------ --> Test 4: 3 Isenbaev A B A B C A Q W --> Answer: A 1 B 1 C 2 Isenbaev 0 Q 2 W 2 ------------------------------ *(All test cases were made by other users, so you'll probably found them in other Posts/Topics/Discussions). Acknowledgments to: -> "Vit Demidenko" & "Nathalie" -> "Pavel Nikolov" -> "mccolt89" -> "Megakrit" -How I solved it: I solved this problem in Java, for that, I used: ->1 java.util.Scanner ->1 java.util.HashMap ->1 java.util.TreeMap ->3 java.util.HashSet ->1 java.util.LinkedList ->? java.util.StringTokenizer (or you can just simply use the Scanner method "next()"). (The structures can be declared inside loops or other structures). Hope all this helped you :)
Edited by author 08.04.2020 00:48 Edited by author 08.04.2020 00:49 Test in you code example like this 4 3 1 5 6 Wrong Answer is 0. Thrue Answer is 3. Be confident!!! Why this piece of code showing wrong answer. I have tested your input it has given correct output. #include<iostream> using namespace std; int main(){ int k, n, arr[101],x=0; cin>>k>>n;
for(int i=0; i<n; i++){ cin>> arr[i];
} for(int i=0;i<n;i++){ if(k>=arr[i]){ if(i != n-1){ x = x + arr[i+1]; arr[i+1] = x;
x = 0;
} else{ x = 0; }
} else{ if(i != n-1){ x = (arr[i]-k) + arr[i+1]; arr[i+1] = x;
} else{ x = arr[i] - k; } } // printf("X : %d\n",x); } if(x<=0) cout<<0; else cout<<x;
} #include<iostream> using namespace std; int main(){ int k, n, arr[101],x=0; cin>>k>>n;
for(int i=0; i<n; i++){ cin>> arr[i];
} for(int i=0;i<n;i++){ if(k>=arr[i]){ if(i != n-1){ x = x + arr[i+1]; arr[i+1] = x;
x = 0;
} else{ x = 0; }
} else{ if(i != n-1){ x = (arr[i]-k) + arr[i+1]; arr[i+1] = x;
} else{ x = arr[i] - k; } } // printf("X : %d\n",x); } if(x<=0) cout<<0; else cout<<x;
} #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector <vector <int>> a(n, vector <int> (n)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; } } int ans = a[0][0]; for (int leng = 1; leng <= n; leng++){ for (int up = 0; up <= n-leng; up++){ vector <long long> sumv(n); for (int j = 0; j < n; j++) { for (int i = up; i < up + leng; i++) { sumv[j] += a[i][j]; } } int sum = 0; for (int r = 0; r < n; ++r) { sum += sumv[r]; ans = max(ans, sum); sum = max(sum, 0); } } } cout << ans; } has anybody got WA8 too? I tried all tests in forum but it didn't help :( Be careful when you implement Manacher's algorithm, when you copy the ready part for the second part, don't forget making all the needed changes, I forgot changing just one sign ! #include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string c = "a"; string word; for (;;) { c = getc(stdin); if (c[0] == EOF) { reverse(word.begin(), word.end()); cout << word; break; } if (((c[0] >= 'a') && (c[0] <= 'z')) || ((c[0] >= 'A') && (c[0] <= 'Z'))) { word.append(c); } else { reverse(word.begin(), word.end()); cout << word << c; word.clear(); } } } instead map use unordered_map once I've solved this exercise, but know a vontto make my algorithm better. I've forced whith WA#12. Could you tell me this test? I've solved it!!))) if you have the same problem, try test: 1233345333 ansver: 12333453335433321 #include <iostream> #include <vector> #include <iterator> using namespace std; int n = 163841; vector<char> prime(n + 1, true); void eratosphen() { prime[0] = false; prime[1] = false; for (int i1 = 2; i1 <= n; ++i1) if (prime[i1]) if (i1 * 1ll * i1 <= n) for (int j1 = i1 * i1; j1 <= n; j1 += i1) prime[j1] = false; } int main() { eratosphen(); vector <long long> list(15001); int i = 2; for (int il = 1; il <= 15000;) { for (int ip = 2; ip < prime.size(); ip++) { if (prime[ip]) { list[il] = ip; il++; } } } int k; cin >> k; for (int i0 = 0; i0 < k; i0++){ int m; cin >> m; cout << list[m] << '\n'; \ } } Sort the quarters that can be crossed.And then dp. The state transition equation is F[i]=Max{ F[j] + 1 | P[j].x<P[i].x and P[j].y<P[i].y } The maximum of F[i] is the number of the the quarters that should be crossed. Then you can work out the answer. Edited by moderator 18.08.2020 02:22 A solution for Chinese readers.Much clearer. 这道题有明显的动态规划策略。首先不要按照方格来考虑,考虑顶点,这样目标点就是(N+1,M+1)。 ---------算法1----------- 最直观的想法是按照矩阵动态规划。 设状态F[i,j]为走到点(i,j)时的最短路径 状态转移方程 F[i,j]=Min { F[i-1,j]+100 F[i,j-1]+100 F[i-1,j-1]+141.4213562373 } 边界条件 F[0,0]=0 F[N+1,M+1]就是结果。 但是对于8M的内存限制,要使用滚动数组。 时间复杂度为O(N*M) ---------算法2----------- 可以发现,如果我们只走直边的话,要走(N+M)*100长度。如果走C条斜边,那么要走(C*141.4213562373)+(N+M-C*2)*100 的长度。那么显然我们要尽可能使C更大,即多走斜边。 这样可以转化为经典的LIS模型。即把所有的斜边按照坐标排序,然后求最长的上升序列(x,y都要严格递增),走这样的斜边一定是最优的策略。于是我们可以求出C。 结果就是(C*141.4213562373)+(N+M-C*2)*100。 Vijos 1336其实就是这道题的数据加大版。对于较小的K和很大的N,M,只能用算法2解决。 by translating............. A solution for Chinese readers.Much clearer. This problem has obvious dynamic programming strategies. First, don't think in terms of squares, consider vertices, so the target point is (N + 1, M + 1). --------- Algorithm 1 ----------- The most intuitive idea is dynamic programming in terms of matrices. Let the state F [i, j] be the shortest path to the point (i, j) State transition equation F [i, j] = Min { F [i-1, j] +100 F [i, j-1] +100 F [i-1, j-1] +141.4213562373 } Boundary condition F [0,0] = 0 F [N + 1, M + 1] is the result. But for the 8M memory limit, a rolling array is used. Time complexity is O (N * M) --------- Algorithm 2 ----------- It can be found that if we only go straight, we have to go to (N + M) * 100 length. If you take the C hypotenuse, then you have to take the length of (C * 141.4213562373) + (N + M-C * 2) * 100. So obviously we want to make C as large as possible, that is, take more hypotenuse. This can be transformed into a classic LIS model. That is, sort all the hypotenuses according to the coordinates, and then find the longest ascending sequence (x, y must be strictly increased). Taking such hypotenuses must be the optimal strategy. Then we can find C. The result is (C * 141.4213562373) + (N + M-C * 2) * 100. Vijos 1336 is actually an enlarged version of this question. For smaller K and large N, M, it can only be solved by algorithm 2. We could solve it by Theorem on the sum of four squares, I wonder how to solve it by DP? If you know, please help me, thank you! We could solve it by Theorem on the sum of four squares, I wonder how to solve it by DP? If you know, please help me, thank you! Well... For n=72... what are the possible squares you can take? You can take 64,49,36,25...4,1 . So what's the best result for 72? The best result Best(72)=min(Best(72-64),Best(72-49),Best(72-36), ... Best(72-1))+1; Now whats the base cases? U see, for all square numbers, u can take it in one go. So Best(1)=Best(4)=Best(9)=Best(16) ... = 1 Its a top down approach. I hope u got the idea... Goodluck. Btw, I'm wondering how u solved by Theorem on the sum of four squares. Can u send your code to my mail please? ealham86@gmail.com i solved it with dp. but i wondered with u.plz send me ur code. EMAIL:achowdhury@isrt.ac.bd I failed on 13 test and I can't found error. Please give a 13 test. |
|