Общий форумCan it be solved with monte carlo alogrithm? I used 10^6 points for checking and got WA at test #10. Then changed number of points to 10^5 and still get WA#10. Edited by author 19.10.2004 02:09 I cut the square into 10^5 stripes and WA #10. Then I magnified the picture by 10^4 times and changed real into extended, WA #10 still. Wrong test, or wrong algo? I used 10^6 points checking and I got AC=) Try to post your code I'm sure the problem there I've solved it with monte carlo alogrithm. So, i can say that it is possible 1000 => 501501000 500 => 62875500 333 => 18629685 1 => 3 3 => 30 4 => 60 But Wa#5 Edited by author 28.10.2006 17:09 The same with me: WA#5 can anybody tell me why Just use int64 instead of longint; My solution is very short and I also get WA5, my answers are the same as those posted, can anyone give some hint ? I got Accepted using BrutForce!!! Already solved this problem, read the hint below :) Edited by author 30.10.2006 21:20 Yes , me , too . WA#5 but AC now , you should change "int n" into "long long n" . Yup, 10x pal, you saved me from reading again and again this task and to wonder where I was wrong :) Who can find my mistake? [code deleted] it passes all my tests, but it can't pass 5 Edited by moderator 29.12.2006 09:16 This is my formula for (int i = 0; i <= n; ++i) res += (i + n) * (n - i + 1) / 2 + i * (n - i + 1); This one is mine: n*-~n*-~-~n>>1 Have fun! Thanks for the advice. Could you tell me what brings this change? n=10000 fits in an int, doesn't it? Ha! Got accepted only with __int64 and not with long long... my djgpp returns a compilation error on such a line... could anybody explain me what should that be? Edited by author 10.11.2006 01:16 Edited by author 02.03.2008 12:54 Edited by author 02.03.2008 12:53 Can somebody tell me the possible reason of this WA? Or at least what figure is in that test? I would be very thankful! please, give me some tests. i tried to solve this problem with dp. O(N*2) time and O(N) memory: here is my code #include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int n; string s,t; string Longest_common_substr(void) { int place; int longest=0; vector<int> m(n); for(int i=0;i<n;i++) { for(int j=n-1;j>=0;j--) { if(s[j]==t[i]) { if(j!=0)m[j]=m[j-1]+1; else m[j]=1; } else m[j]=0; if(m[j]>longest) { longest=m[j]; place=j-longest+1; } if(longest==n)return s.substr(place,longest); } } if(longest==0)return ""; else return s.substr(place,longest); } int main() { ios::sync_with_stdio(0); cin.tie(); cin>>n; cin>>s; cin>>t; cout<<Longest_common_substr()<<endl; return 0; } can you please suggest any modifications? I have WA 1 but on my computer all ok. Is first test not like in statement? num = int(input()) arr = [] for i in range(num): arr.append([]) for j in range(num): arr[i].append([])
check = 1 for i in range(num-1,-1,-1): x = 0 y = i while y != num: arr[x][y] = check check += 1 y += 1 x += 1 for i in range(1,num,1): x = i y = 0 while x != num: arr[x][y] = check check += 1 y += 1 x += 1 string = '' for i in range(num): for j in range(num): string += (str(arr[i][j]) + ' ') print(string) string = '' num = int(input()) arr = [] for i in range(num): temp_arr = input().split(' ') arr.append(temp_arr) string = '' for i in range(num): k = i j = 0 while k >= 0: string += (arr[k][j] + ' ') k -= 1 j += 1 for i in range(1,num,1): k = num - 1 j = i while j != num: string += (arr[k][j] + ' ') k -= 1 j += 1 print(string) Edited by author 27.07.2013 13:58 Edited by author 27.07.2013 13:58 The problem say that "It is guaranteed that during the experiment each time a coin was to be removed the stack was not empty." But when I submit such a brute force code: -------------------- if (x > 0) a[t++] = x; else if (x == 0) { if (t + t < maxn) { copy(a, a + t, a + t); t += t; } } else printf("%d\n", a[--t]); -------------------- It crashed at #42. Then, I modified the last "else branch" into: -------------------- else if (t) printf("%d\n", a[--t]); -------------------- I got WA at #42. What if t = maxn/2 + 1 and than t + 1 pop operations? For example: 1000000 1 0 0 .. 0 (20 times) -1 -1 .. -1 (1000000 - 21 times) You will store only 2^19 copies in array, and get crash Oh..Sorry..It's my fault. I only set the size of a to 1000001 * 2, but I forgot to modify the maxn.... I apologize for asking so stupid question.T_T Accepted now, thank you very much. Yeah,I've made the same mistake,and thank you so much! #include<iostream> #include<stdio.h> #include<string.h> using namespace std; char v[53];int ch[53]; char vi[53][5],*punt=NULL,vf[53],vc[53],vp[53],*a,vt[53],chr[3]; int maxl=0,maxt=0,k,b,max2,l=0; int n,j=0,i,ind; main() { gets(v); n=strlen(v); if(n==1){cout<<v;} else{ for(i=0;i<n-1;i++) { // carga inicial vi[i][0]=v[i] ; vi[i][1]=v[i+1] ; ch[i]=0; } for(i=0;i<n-1;i++) { punt=strstr(v,vi[i]); if(punt!=NULL) { ch[punt-v]++; } } for(i=0;i<n-1;i++) { if(ch[i]>maxt) { maxt=ch[i]; ind=i; } } strcpy(vc,vi[ind]); strcpy(vp,v); punt=strstr(v,vi[ind]); i=0; strcpy(vf,vi[ind]); if (maxt!=0) { while(1) { b=1; punt=strstr(v,vf); chr[0]=punt[2+l]; strcat(vf,chr); k=2+l; k++; l++; if(l==strlen(punt))break; max2=0; strcpy(vp,v); while(1) { punt=strstr(vp,vf); if(punt!=NULL) { j=strlen(punt); for(i=0;i<j-1;i++) { vp[i]=punt[i+1]; } vp[i]='\0'; max2++; if (max2>=maxt) { maxt=max2; strcpy(vc,vf); b=0; } } if(punt==NULL)break; } if(b==3) break; } } cout<<vc; }} New tests were added to the problem. First tests were replaced with examples from the problem statements. 106 authors have lost AC after the rejudge. I have used manacher'a algorithm and tried all the test cases discussed in these discussions and getting correct solution.... I have used manacher for even and odd palindromes separately and found the longest and if longest comes again... as in the same length..take the smaller start.. but now,... I got WA #7 ...I initially faced some problem in compilation too..please suggest some test case P.S. : m doing while(getline(cin,string)) and also tried while(cin>>string) is something to be done here...please suggest Got AC...small error in code: basically typo :D It's just bruteforce task. if string is like : abcdef you can tranform it like: ^#a#b#c#d#e#f#$ so,even and odd palindromes all is transformed like odd palindromes. What in test #8? Edited by author 25.07.2013 00:58 Admins, give me some tests, please. i am understand!! need to write std::scanf("%d", &a); insteadd of std::scanf("%i", &a); my method is DP: //invite int sum = 0; for (Integer c : guest.children) { sum += DP[c.intValue()][0]; } DP[index][1] = sum + RATE[index]; // do not invite sum = 0; for (Integer c : guest.children) { int max = Math.max(DP[c.intValue()][0], DP[c.intValue()][1]); sum += max; } DP[index][0] = sum; at first, I got WA on 13#, DP the tree should from leaf to root, but at first I sort the guests by its children count, the right way is sort the guests by depth Edited by author 25.07.2013 09:50 #include <iostream> #include <math.h> using namespace std; void main(void) { int a,b,c; cin>>a>>b; c=0; c=a/2+a%2+b/2+b%2;
if (((a==1)&&(b!=1))||((a!=1)&&(b==1))) { c=c-1; } if (c%2) cout <<"[:=[first]" ; else cout <<"[second]=:]" ;
} whot is wrong? Edited by author 25.07.2013 00:45 |
|