| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| My Accepted Code | Paata Julakidze | 1295. Бред | 9 июл 2013 16:04 | 1 |
Edited by author 09.07.2013 16:05 |
| Hi | Killlo(UFA) | 1000. A+B Problem | 9 июл 2013 15:13 | 1 |
Hi Killlo(UFA) 9 июл 2013 15:13 Hello Edited by author 09.07.2013 15:24 Edited by author 09.07.2013 17:20 |
| If you have WA14 | Birne Ageev [USU] (Psych up club) | 1101. Робот в поле | 9 июл 2013 02:29 | 1 |
Last symbol of first string is space. |
| WA#3 Please help | George Agapov | 1078. Отрезки | 8 июл 2013 22:56 | 4 |
My solution: http://pastebin.com/BVfebbpv I used such algorithm: 1) sort of each point (it seems to work correctly on tests with same coordinates) 2) walk through sorted array of points, making dp on every segment with two variables (maxi and maxv) to indicate maximum value we can reach in this segment and id of inside segment, corresponding to this maaximal value I tried almost all tests from topics and lots, invented by myself and can't get what's wrong with my solution. try this 8 1 10 2 3 4 5 6 7 8 9 20 30 21 29 22 28 answer 3 8 7 6 I also had WA#3, but this test is AC. My solution used BFS. Please, help me! Thanks! #pragma comment(linker,"/STACK:8000000") #include <stdio.h> int loading(int &N,int** (&M)){ int *Left,*Right; scanf("%d",&N); if(N==0) {printf("%d",0); return -1;} Left=new int[N]; Right=new int[N]; int tmpL,tmpR; for(int i=0;i<N;++i) {scanf("%d %d",&tmpL,&tmpR); /*if(tmpR<tmpL) {int tmp=tmpR; tmpR=tmpL; tmpL=tmp;}*/ Left[i]=tmpL; Right[i]=tmpR;} M=new int*[N]; for(int i=0;i<N;++i) {M[i]=new int[N]; for(int j=0;j<N;++j) M[i][j]=0;}
//i-ый отрезок вложен в j-ый for(int i=0;i<N;++i) for(int j=0;j<N;++j) if(Left[j]<Left[i] && Right[i]<Right[j]) {M[i][j]=1; M[j][i]=-1;} delete[] Left;delete[] Right; return 0; } int doing(int &N,int **(&M),int *(&Last),int &posBiggestWeight,int &BiggestWeight){ Last=new int[N]; int *Weight=new int[N]; for(int i=0;i<N;++i) {Last[i]=-1; Weight[i]=0;}
//Поиск отрезков, которые ни во что не вложены int *Roots=new int[N],iCountRoots=0; for(int i=0;i<N;++i){ bool isNotRoot=true; for(int j=0;j<N && isNotRoot;++j) if(M[i][j]==1) isNotRoot=false; if(!isNotRoot){ Roots[iCountRoots++]=i; } } //Перебор всех вложеных for(int k=0;k<iCountRoots;++k){ int NeedVisit[1000000],cntNVisit=0; NeedVisit[cntNVisit++]=Roots[k]; Weight[Roots[k]]=0; while(cntNVisit>0){ int tekVertex=NeedVisit[--cntNVisit],tekWeight=Weight[tekVertex],newWeight=tekWeight+1; for(int j=0;j<N;++j) if(M[tekVertex][j]==1 && newWeight>=Weight[j]){ NeedVisit[cntNVisit++]=j; Weight[j]=newWeight; Last[j]=tekVertex; } } } //поиск максимального веса BiggestWeight=-2; posBiggestWeight=-1; for(int i=0;i<N;++i) if(Weight[i]>BiggestWeight){ posBiggestWeight=i; BiggestWeight=Weight[i]; } delete[] Weight; return 0; } int saveing(int &N,int* (&Last),int &posBiggestWeight,int &BiggestWeight){ int *Answer=new int[BiggestWeight+1],pos=posBiggestWeight; int indAnswer=BiggestWeight; while(pos!=-1){ Answer[indAnswer--]=pos+1; pos=Last[pos]; } printf("%d\n",BiggestWeight+1); for(int i=0;i<BiggestWeight;++i) printf("%d ",Answer[i]); printf("%d\n",Answer[BiggestWeight]); delete[] Answer; return 0; } int main(){ int N,**M,*Last,posBiggestWeight=0,BiggestWeight=0; int res=loading(N,M); if(res==-1) return 0; doing(N,M,Last,posBiggestWeight,BiggestWeight); saveing(N,Last,posBiggestWeight,BiggestWeight); delete[] Last; for(int i=0;i<N;++i) delete[] M[i]; delete[] M; return 0; } |
| Very easy solution! | smolcoder | 1794. Шедевры мировой архитектуры | 8 июл 2013 22:01 | 9 |
1) Don't forget, that pupils sit in a circle! 2) You have to count how many pupils you can satisfact with choice 'i' boy at first (even he doesn't to be so :-) ). There are algo claimed O(n) 3) If you have such info, it's so easy to calculate the answer ;-) I can send the solution to your mail. This algo gets TL too... plz send me code to rockprogressive.s[at]gmail.com Hi, Yes the problem can be solved by thinking about it as a voting problem. Consider the following input: 5 3 3 1 5 5 1st student wants 4th student to go first. 2nd student wants 5th student to go first. 3rd student wants 3rd student to go first. 4th student wants 5th student to go first. 5th student wants 1st student to go first. 5th student receives the maximum votes so answer is 5. Consider another example from the problem test case. 4 4 1 2 3 1st student wants 2nd student to go first. 2nd student wants 2nd student to go first. 3rd student wants 2nd student to go first. 4th student wants 2nd student to go first. So, the answer is 4. Another example from a test case taken from elsewhere in the forum: 8 1 2 3 5 5 6 7 8 1st student wants 1st student to go first. 2nd student wants 1st student to go first. 3rd student wants 1st student to go first. 4th student wants 8th student to go first. 5th student wants 1st student to go first. 6th student wants 1st student to go first. 7th student wants 1st student to go first. 8th student wants 1st student to go first. So the answer is 1. Edited by author 10.01.2011 04:57 My solution: Calc b[i] - count of numbers such (n+A[i]-i)%n == i Then find max_idx - index of maximum element in array b answer is (n - max_idx) % n + 1 did you get AC? I don't think to satisfy most students is right. for example(the one you mentioned): 5 3 3 1 5 5 your answer is 5,so the sequence is 2 3 4 5 1. we can calculate the difference: |3-2|+|3-3|+|1-4|+|5-5|+|5-1|=8 but for another sequence:1 2 3 4 5,the difference is: |3-1|+|3-2|+|1-3|+|5-4|+|5-5|=6, is smaller than 8. so as my conclusion, we should make the "displeasure" minimal. if using your method, maybe a lot of students is "satisfied(the difference of him is 0)", but others maybe larger. sorry for my bad English. did you get AC? I don't think to satisfy most students is right. for example(the one you mentioned): 5 3 3 1 5 5 your answer is 5,so the sequence is 2 3 4 5 1. we can calculate the difference: |3-2|+|3-3|+|1-4|+|5-5|+|5-1|=8 but for another sequence:1 2 3 4 5,the difference is: |3-1|+|3-2|+|1-3|+|5-4|+|5-5|=6, is smaller than 8. so as my conclusion, we should make the "displeasure" minimal. if using your method, maybe a lot of students is "satisfied(the difference of him is 0)", but others maybe larger. sorry for my bad English. Hi, Yes the problem can be solved by thinking about it as a voting problem. Consider the following input: 5 3 3 1 5 5 1st student wants 4th student to go first. 2nd student wants 5th student to go first. 3rd student wants 3rd student to go first. 4th student wants 5th student to go first. 5th student wants 1st student to go first. 5th student receives the maximum votes so answer is 5. Consider another example from the problem test case. 4 4 1 2 3 1st student wants 2nd student to go first. 2nd student wants 2nd student to go first. 3rd student wants 2nd student to go first. 4th student wants 2nd student to go first. So, the answer is 4. Another example from a test case taken from elsewhere in the forum: 8 1 2 3 5 5 6 7 8 1st student wants 1st student to go first. 2nd student wants 1st student to go first. 3rd student wants 1st student to go first. 4th student wants 8th student to go first. 5th student wants 1st student to go first. 6th student wants 1st student to go first. 7th student wants 1st student to go first. 8th student wants 1st student to go first. So the answer is 1. Edited by author 10.01.2011 04:57 I got AC for voting solution... 4 4 1 2 3 1st student wants 2nd student to go first. 2nd student wants 2nd student to go first. 3rd student wants 2nd student to go first. 4th student wants 2nd student to go first. So, the answer is 4. typo i'd rather like this. cuz it's clear :) |
| If you have WA #5 | bsu.mmf.team | 1969. Гонконгский трамвай | 8 июл 2013 17:42 | 1 |
You should just pay attention to the sentence: "The last tram leaves from the Shau Kei Wan station BEFORE the first tram finishes its first cycle". Therefore the solution you found may not be correct. Good Luck! |
| Wrong Answer 13 | Kanishk Kanoria | 1868. Конкурс прогнозов | 8 июл 2013 03:30 | 2 |
What is test case 13? Getting a wrong answer on that case. I had WA13 on FreePascal with TStringList.IndexOf() method. Try write IndexOf (or what you use) "manually". Perhaps this is due to hidden features of string conversion/comparison. |
| WA test #6 | idemura | 1029. Министерство | 7 июл 2013 06:25 | 1 |
My code: What's wrong??? #include <algorithm> #include <vector> #include <utility> #include <stdio.h> #define ARRAY_SIZEOF(a) (sizeof(a) / sizeof(a[0])) #define INF 0x7fffffff using namespace std; typedef long long int lli; int M, N; int C[100][500]; int T[101][500]; int m1[500]; int m2[500]; int path[500*500]; int main() { #ifndef ONLINE_JUDGE freopen("in", "r", stdin); #endif int i, j, k; scanf("%d%d", &M, &N); for (i = 0; i < M; i++) { for (j = 0; j < N; j++) { scanf("%d", &C[i][j]); C[i][j]++; T[i+1][j] = INF; } } for (i = 1; i <= M; i++) { m1[0] = T[i-1][0] + C[i-1][0]; for (j = 1; j < N; j++) { m1[j] = min(m1[j-1], T[i-1][j]) + C[i-1][j]; } m2[N-1] = T[i-1][N-1] + C[i-1][N-1]; for (j = N-1; j-- > 0; ) { m2[j] = min(m2[j+1], T[i-1][j]) + C[i-1][j]; } for (j = 0; j < N; j++) { T[i][j] = min(m1[j], m2[j]); } } int jmin = 0; for (j = 1; j < N; j++) { if (T[M][j] < T[M][jmin]) { jmin = j; } } i = M; j = jmin; k = 0; do { path[k++] = j + 1; int m = T[i-1][j]; jmin = j; if (j-1 >= 0 && T[i][j-1] < m) { jmin = j-1; m = T[i][jmin]; } if (j+1 < N && T[i][j+1] < m) { jmin = j+1; m = T[i][jmin]; } if (m == T[i-1][j]) i--; else j = jmin; } while (i); for (i = 0; i < k; i++) { printf("%d ", path[k-1-i]); } printf("\n"); return 0; } |
| For the TLEers | [NKU]sweet | 1500. Разрешения на проезд | 6 июл 2013 23:55 | 2 |
I sort the the 2^k states by the bits it contains, then check the states in order, and always TLE #22 Then, I choose a state randomly in the 2^k states and check if it's legal, and get accepted…… part of my code: 63 int ans = (1 << k) - 1; 64 int tot = 1 << k; 65 int times = 0; 66 while (tot > 0 && (times * realm < (500000000))) { 67 int now = rand() % tot; 68 if (countBit(arr[now]) < countBit(ans)){ 69 memset(visit,0,sizeof(visit)); 70 times++; 71 if (dfs(0,arr[now])) { 72 ans = arr[now]; 73 } 74 } 75 arr[now] = arr[--tot]; 76 } If you use G++, it's better to use standart function (__builtin_popcount(n)) instead of countBit(n) |
| WA#25 | askhatik | 1274. Fractional Arithmetic | 6 июл 2013 22:49 | 1 |
WA#25 askhatik 6 июл 2013 22:49 try this test: 11 + 11 ##### 22 |
| O(n log n) | linjek | 1297. Палиндромы | 6 июл 2013 20:10 | 1 |
Для каждого места (буквы + расстояния между ними) будем проверять длину макс подпалиндрома с помощью бин поиска (его длину). Осталось за О(1) проверить является ли эта подстрока палиндромом, что можно сделать с помощью хешей (заранее посчитать хэш для каждого префикса, и высчитывать хэш подстроки в обе стороны и сравнивать) |
| WA with test#15 | Md. Kamrul Islam | 1161. Stripies | 6 июл 2013 17:16 | 2 |
I am getting WA for test#15 with my C++ code. Is there anybody who can give an explanation why this is happening? Try a to test with two same masses: 5 11 13 21 10000 10000 Then when you will understand what was your problem you will use std::multiset<double, std::greater<double>> s; Cheeres! ;) |
| Time Limit Exceed #8 (Java) | Mad_Sanek | 1110. Степень | 6 июл 2013 15:07 | 2 |
import java.math.BigInteger; import java.util.Scanner; public class Main { public static BigInteger step(int a, int b) { BigInteger temp=BigInteger.valueOf(a); for (int i=1; i<b; i++) { temp=temp.multiply(BigInteger.valueOf(a)); } return temp; } public static void main(String[] args) { Scanner inp=new Scanner(System.in); int n=inp.nextInt(); int m=inp.nextInt(); int y=inp.nextInt(); boolean f=false; for (int i=0;i<m;i++) { BigInteger x=step(i,n); BigInteger c=x.mod(BigInteger.valueOf(m)); if (c.compareTo(BigInteger.valueOf(y))==0) { System.out.print(i+" "); f=true; } } if (f==false) System.out.print("-1"); } } I don't know how to do it faster, than now. Please help me. Edited by author 03.02.2013 15:10 you don't need to use BigInteger =) |
| For those who have TLE on 15 | vicproon | 1671. Паутина Ананси | 5 июл 2013 21:48 | 2 |
I had the same problem, and solved it after changing all c++ io functions from <iostream> to <cstdio> Thanks, your hint really helped me. The same thing in Java. I had TLEon15. After I replaced Scanner with my custom input parsing I had got AC. |
| Неправильная формулировка? | vb002 | 1578. Охота на мамонта | 5 июл 2013 18:56 | 1 |
Почему в условии задачи сказано, что начальная и конечная точки маршрута фиксированы, а в примерах конечные точки получаются разными? Edited by author 08.07.2013 01:51 |
| What is optimal asymptotic? | Vladimir Plyashkun [CSU] | 1941. Страшное марсианское слово | 5 июл 2013 00:10 | 2 |
What is optimal asymptotic for this problem? My algo has O(M*log(N)) where N - length of scary Martian word, and M - length of text of Ovchinnikov's book, but i have TLE on 21th test O(M + N) is optimal. But maybe you can succed with your asymptotic if use fast I/O |
| Admins. Why did you remove Java? | d3m0n1c | 1220. Stacks | 4 июл 2013 20:51 | 3 |
Better correct the memory usage by Java programs. You can simply decrease memory by 200 KB or just increase memory limits for some problems that can't be solved on Java or C#. Язык запрещен для данной задачи Language is not allowed for this problem Edited by author 26.04.2013 17:32 I also can't understood why Java is disallowed now. Even if java solution is not so fast as C/C++/Pascal, it's iteresting to make some optimisations to java solution, to get accepted. Please, accept Java for this problem. Now empty Java 1.7 program takes only 116Kb, so 750kb would be enought to make a solution. Edited by author 05.07.2013 13:04 |
| combinatorics | staticor | 1142. Отношения | 4 июл 2013 20:32 | 1 |
use DP, mainly involved with: permutation and combination A(n,k) C(n,k) or, you can think about there is a x-Axis. two points (a, b) can be placed --a--b-- --b--a-- || --(ab)-- the first two solution has two groups, and the last one has one groups for the overlap.
|
| Solution | MSDN | 1571. Переводчики | 4 июл 2013 19:43 | 3 |
This problem is very easy!. if N=1 output is 0; if N=2 and first language=second language output is 0; if N=2 and first language not = second language output "first"-"second" (fist and second - it's name of language) If N>2 if there are two or many equal languages output "Impossible" If N>2 if all languages different you print N and print all name languages this your language. Your language it is thought up string of latin letters. But dangerous this it. your language will be string len<10 and latin letters in small case. Tests: input: 1 a output: 0 input: 2 a a output: 0 input: 2 a b output: a-b input: 3 a b c output: a-qwerty b-qwerty c-qwerty input: 3 a a b output: Impossible There is one more case when N>2 and all languages are the same. Re: Solution Anupam Ghosh, Wipro Technologies 4 июл 2013 19:43 "There is one more case when N>2 and all languages are the same". As per problem " Developers also settled if two crews are communicating then other crews must not understand a word because in that case other crew will listen instead of work and towers will not be constructed by the time". Hence the output should be "Impossible" for this case. |
| test 5 | Roman | 1014. Произведение цифр | 3 июл 2013 22:35 | 1 |
tell me, please, what input in test 5. |