Общий форумwhat can i do if i struck on a problem,becoz there are no solutions n hints availabe here :( 1. Lay down. 2. Cry of despair. 3. Try to think of a more effecient solution or learn some new algos. 4. Use google and sometimes you can find hints for your task or even some solutions shared around the net. Good luck! hahaha..thanks but google does not help all the time :( for(int m=i+2;m<=j;m++) if((m-i)%2==1) { t2+=t1; if(t2<-8000000000LL||(t2>8000000000LL))//Look at this line. break; } else { t1+=t2; if(t1<-8000000000LL||(t1>8000000000LL))//Look at this line. break; } ---- Sorry for my bad English You can also do equation system (IDK if it's the correct name). You can make two equations, with two incognitas. It can be solved because you have the same amount of equations and incognitas. Be careful, it's easier with java big integer rather than C++ long long or long double. F1 = 1 F4 = 4 what numbers are F2 and F3? F2 = F1+F0 F3 = 2*F1+F0 F4 = 3*F1+2*F0 F0 == 0.5??? anzhig@inbox.ru Edited by author 20.07.2012 18:56 In the problem says: "is an infinite sequence of integers" So, this is an invalid sequence. why wrong answer?? help please. var a,b,c,d:integer; begin readln(a,b); c:=10-a; d:=10-d; writeln(c); writeln(d); end. с чего ты взял, что банок 10? там сказано, что не более 10! а сколько именно нам неизвестно ну тогда напиши так,чтобы тот кто компилирует имел возможность вводить свое число А ещё надо помнить, что последнюю банку они прострелили оба. Why always Memory limit exceeded??? It is so wired. package com.island.timus.ahundrend; import java.util.Scanner; public class T1003_Parity { public static void main(String[] args) { Scanner in = new Scanner(System.in); int length = in.nextInt(); while (length != -1) { int[][] friendsAndEnemies = new int[2][length + 1]; for (int j = 0; j < length + 1; j++) { friendsAndEnemies[0][j] = j; friendsAndEnemies[1][j] = -1; } int conditions = in.nextInt(); int counter = 1; for (int i = counter; i <= conditions; i++, counter++) { Term.start = in.nextInt(); Term.end = in.nextInt(); Term.parity = in.nextLine(); if (Term.start > length || Term.end > length) { break; } if (Term.parity.trim().equals("even")) { join(friendsAndEnemies[0], Term.start - 1, Term.end); } else { int eneymyAncestor1 = findAncestor(friendsAndEnemies[0], Term.start - 1); int eneymyAncestor2 = findAncestor(friendsAndEnemies[0], Term.end); if (friendsAndEnemies[1][Term.start - 1] == -1 && friendsAndEnemies[1][Term.end] == -1) { friendsAndEnemies[1][Term.start - 1] = eneymyAncestor2; friendsAndEnemies[1][Term.end] = eneymyAncestor1; } else if (friendsAndEnemies[1][Term.start - 1] != -1 && friendsAndEnemies[1][Term.end] == -1) { join(friendsAndEnemies[0], friendsAndEnemies[1][Term.start - 1], Term.end); friendsAndEnemies[1][Term.end] = eneymyAncestor1; } else if (friendsAndEnemies[1][Term.start - 1] == -1 && friendsAndEnemies[1][Term.end] != -1) { join(friendsAndEnemies[0], friendsAndEnemies[1][Term.end], Term.start - 1); friendsAndEnemies[1][Term.start - 1] = eneymyAncestor2; } else { join(friendsAndEnemies[0], friendsAndEnemies[1][Term.end], Term.start - 1); join(friendsAndEnemies[0], friendsAndEnemies[1][Term.start - 1], Term.end); } } int pause = check(friendsAndEnemies); if (pause == friendsAndEnemies[0].length) { continue; } else { break; } } System.out.println(counter - 1); for (int i = counter + 1; i <= conditions; i++) { int x = in.nextInt(); int y = in.nextInt(); String z = in.nextLine(); } length = in.nextInt(); } } private static int findAncestor(int[] friends, int value) { int r = value; while (r != friends[r]) { r = friends[r]; } return r; } private static void join(int[] pre, int x, int y) { int ancestorX = findAncestor(pre, x); int ancestorY = findAncestor(pre, y); int r = y; if (ancestorX != ancestorY) { while (r != pre[r]) { int temp = pre[r]; pre[r] = ancestorX; r = temp; } pre[ancestorY] = ancestorX; } } private static int check(int[][] friendsAndEnemies) { int i = 1; for (; i < friendsAndEnemies[0].length; i++) { int friendAncestor = findAncestor(friendsAndEnemies[0], friendsAndEnemies[0][i]); int enemyAncestor = -1; if (friendsAndEnemies[1][i] != -1) { enemyAncestor = findAncestor(friendsAndEnemies[0], friendsAndEnemies[1][i]); } if (friendAncestor == enemyAncestor) { break; } else { continue; } } return i; } } class Term { public static int start; public static int end; public static String parity; } below is my java code: import java.util.*; public class timus1581 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); if (t>=1 && t<=1000) { int i = 0; int cnt = 0; int a[] = new int[t]; for (i = 0; i <= t-1; i++) { a[i] = sc.nextInt(); if (a[i]>=1 && a[i]<=10) { continue; } else { System.exit(0); } } for (i = 0; i < t-1; i++) { if (a[i] == a[i+1]) { cnt++; } else { System.out.print((cnt+1) + " " + a[i] + " "); cnt = 0; } if (t == i + 2) { System.out.print((cnt+1) + " " + a[i]); cnt = 0; } } } } } Edited by author 09.04.2016 14:32 System.out.println("Enter no. of test cases"); System.out.println("Enter Integers"); How do you think a robot would distinguish those messages from your real answer. http://acm.timus.ru/help.aspx?topic=judge«The program must print only the data that is required by the problem statement. The program must not print any prompts (“Enter N:”). The program must not wait for pressing a key at the end of execution.» for (i = 0; i < t-1; i++) { if (a[i] == a[i+1]) { cnt++; } else { System.out.print((cnt+1) + " " + a[i] + " "); cnt = 0; } if (t == i + 2) { System.out.print((cnt+1) + " " + a[i]); cnt = 0; } } I am not understand this part. Edited by author 12.06.2016 13:59 Hi! My code has complexity O(2^N) and it had AC in 0.001 sec. A friend of mine noted this: when I run my program in this case: 50 50 1 2 3 4 5 6 ... Same pattern here 95 96 97 98 99 100 And it will give TLE. Please, add this case! 50 50 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 email: ruben.ashughyan@gmail.com Edited by author 01.11.2017 22:56 Edited by author 12.05.2021 20:35 Edited by author 01.06.2014 20:04 my code is running correctly but yet it fails at test 1 :( Can you add Rust language compiler? Edited by author 11.06.2016 16:54 Just a passing note: the same exact code gets TLE in G++ but AC in Visual C++ (with a very comfortable margin). Make sure to test your code in both compilers before making a judgement that your code is too slow, for those who are coding in C/C++. That's ridiculous for some reason. TLE in G++ but AC in Visual C++ without a single edit in the source code. wow, the same one problem Here is my Solution. As this problem is related to stable sort and there is built in stable_sort function in c++ so it has become easier #include <bits/stdc++.h> using namespace std; bool compare( const pair<long long int,long long int>& x, const pair<long long int, long long int>& y ) { return (x.second>y.second); } int main() { vector<pair<long long int,long long int> >a; long long int n,i,j,b,c; cin>>n; for(i=1;i<=n;i++) { cin>>b>>c; a.push_back(pair<long long int,long long int>(b,c)); } stable_sort(a.begin(),a.end(),compare); //must include stable_sort vector<pair<long long int,long long int> >::iterator p; for(p=a.begin();p!=a.end();p++) { cout<<p->first<<" "<<p->second<<endl; } return 0; } Edited by author 11.06.2016 01:55 Whats wrong with my code. I get correct answer for Test 6 on my compiler, but when I submit the solution, I get wrong answer. Please help!! I tried with below values and got correct answer 4 3 3 4 5 Correct answer: 1 #include <iostream> using namespace std; int main() { int a,k,n,d; int b=0; cin>>k>>n>>d; for (int i=0;i<n-1;i++) { cin>>a; a=a-k; b=b+a; } if (d-k>=0) { if (b+d-k>=0) cout<<b+d-k; else cout<<0; }
else if (b>0) cout<<b; else cout<<0; char f; cin>>f; } I have some problem, try 5 4 3 , you must have 0. I used Dijkstra+heap optimized but still got TLE on #11.. Is there some better algorithm? help.. my email:caoyuan@mail.ustc.edu.cn thx. Try to use numbers instead of strings How to cope with the strings? I put all strings to a map, then for each string I construct all possible neighbours and then I check if they are in a map. So I have to deal with 50000 * 135 * 16 = 108 000 000 operations. It is too much. I can use a hash table. However, is there any simpler solution than using the hash table? You can use strings (because it's so conveniently), but you have to forget about std::map. Use unordered_map<string> (or your hash table) instead of it. I had TLE on test 11 with std::map, but when I changed map to unordered_map, I got AC with not bad time. I think it's easier than use numbers instead of strings. What is wrong #include <cstdio> unsigned long int contador[65535]; void carga() { for(int i=0;i<65535;i++) { if(i==0) contador[i] = 1; else contador[i] = contador[i-1] + i; }} bool busqueda(unsigned long int k[], int i) { bool buscador = false; int inf = 0, sup = 65534, centro; while(inf <= sup) { centro = ((sup - inf) / 2) + inf; if(contador[centro] == k[i]) { buscador = true; break; } if(contador[centro] < k[i]) { inf = centro + 1; } if(contador[centro] > k[i]) { sup = centro - 1; }} return buscador; } int main() { carga(); unsigned long int k[65535]; int n, i; scanf("%d", &n); for(int i=0;i<n;i++) { scanf("%lud", &k[i]); } for(i=0;i<n-1;i++) { if(busqueda(k, i)) printf("1 "); else printf("0 "); } if(busqueda(k, i)) printf("1"); else printf("0"); printf("\n"); } i am also getting WA at 5 It was very easy. Backtracking(перебор с возвратом) I think that it is hard problem and has exp(n) complexity. If remove psevdopractic decoration it is to solve a system boolean equation of 100 unknows Xi with type of Xi^Xj=0; (NotXi)^Xj=0;(NotXi)^(NotXj)=0. Amount of equation is near 10000. Thus we have easy problem for weak tests and very hard problem for detailed test. This situation was brightly shoun for identical Ships problems.Programmers should create code working on all possible tests in prescribed range of variables. Now I am also having Ac(0.031) by using backtracking. I have applied this method to boolean problem not to Graf. But I fear that we all will lost our submits if problem will be rejudged. In worst case in complexy is O(n^2) Yes, it's O(N^2). And resembles another problem of this type: 1382 does transitive closure algorithm work here? Just a standard 2-SAT problem. . Edited by author 13.06.2016 15:16 |
|