Common BoardWrong answer in test №17 Me too. Who knows how to resolve this problem? 0 0 0 0 0 0 0 0 10 30 Answer: 50 60 0 0 0 0 0 0 0 10 10 30 Answer: 60 90 0 0 0 0 0 0 0 10 10 21 Answer: 51 81 0 0 0 0 0 0 0 10 10 20 Answer: 40 80 Edited by author 11.07.2016 13:21 >> 0 0 0 0 0 0 0 10 10 21 : min = 51 - how ?? last frame: [ 10 , 10 , 1 ]-> gets min=51, but last frame: [ 1 , 10 , 10 ] - > gets min = 42 --> why this is not possible? [ 1 , 10 , 10 ] is not possible because there are only 9 pins after the first roll here. So you cannot knock down 10 pins in the second roll. http://ideone.com/06yGHW Maybe someone could improve that solution and get AC with it. Current status of that code is WA#8. I think it is quite boring and tedious to upgrade it to AC. Maybe you can see how to upgrade it with small effort. Incredible, my code contained a mistake. Mistake was that I wrote not q=go[q]. next [ch], but simply go[q]. next [ch]. Strange enough, compiler didn't warned me about unused variable. So, the problem can be solved using DFS+Trie in 15 ms. Edited by author 15.07.2017 21:56 Edited by author 15.07.2017 21:56 #include <stdio.h> #include <algorithm> #include <stack> using namespace std; #define MAXN 100 #define MAXM 10 int ship[MAXN]; int row[MAXM]; int exi[MAXN]; int N, M; int cmp(const void* a, const void* b); void divid(int m); int main() { scanf("%d%d", &N, &M); for(int i=0; i<N; i++) scanf("%d", &(ship[i])); for(int i=0; i<M; i++) scanf("%d", &(row[i]));
for(int i=0; i<N; i++) exi[i] = 1;
qsort(ship, N, sizeof(int), cmp); divid(M);
return 0; } int cmp(const void* a, const void* b) { int* x = (int*)a; int* y = (int*)b; return *y - *x; } void divid(int m) { if(m > 1) divid(m-1);
stack<int> s; int tot = row[m-1]; int hav = 0; int i = 0; for(;;){ while(i<N && (!exi[i] || ship[i]>(tot-hav))) i++; if(i >= N){ for(;;){ i = s.top(); s.pop(); hav -= ship[i]; exi[i] = 1; i++; if(i < N) break; } continue; } s.push(i); hav += ship[i]; exi[i] = 0; i++; if(hav == tot){ int sh_ind; int siz = s.size(); printf("%d\n", siz); while(!s.empty()){ sh_ind = s.top(); s.pop(); printf("%d ", ship[sh_ind]); } printf("\n"); return; } } } #################################################### I used recursion alg. And I know there is error in this code because I didn't deal with the situation I called "data confliction" such as "5 = 2+3".But how to IMPROVE it ??? email:1813484947@qq.com Edited by author 15.07.2017 20:00 Edited by author 16.07.2017 15:23 Pozhaluysta, kto-nibud', dayte mne hot' kakie testy k zadache 1070! A to vse testi, kotoriye u menya yest' moya programma prohodit, no na teste #1 dayot nepravil'niy otvet! I obyasnite, pochemu mozhet byt' test: "12.00 15.00 01.02 03.07 Answer: 0" ? Yes you Answer 0; 1) 23.42 01.14 08.10 17.51 Answer: 4 2) 01.01 10.59 04.23 04.22 Answer: 5 3) 12.00 15.00 01.02 03.07 Answer: 0 4) 23.58 00.43 22.27 03.10 Answer: 2 5) 12.00 15.00 20.00 21.00 Answer: 1 6) 01.01 21.59 04.23 11.22 Answer: 5 Yes you Answer 0; 1) 23.42 01.14 08.10 17.51 Answer: 4 2) 01.01 10.59 04.23 04.22 Answer: 5 3) 12.00 15.00 01.02 03.07 Answer: 0 4) 23.58 00.43 22.27 03.10 Answer: 2 5) 12.00 15.00 20.00 21.00 Answer: 1 6) 01.01 21.59 04.23 11.22 Answer: 5 Can you explain me why on test 6 -> answer is 5 ? Edited by author 28.12.2006 20:13Please, explain me why the answer is 5? answer is 5, because max difference in time = 5 hours)) then all answers >5 , =5 ! Edited by author 28.09.2009 21:26 There should be min(12 - h, h) instead of min(h, 5), test: 01.00 00.00 00.00 03.00 Answer 2 my programe can pass all your tests#,but i WA at ural's test#1,why...? does someone can help me? #include <stdio.h> main() { int i,j,k;
scanf("%lf%lf%lf%lf",&ch[1],&ch[2],&ch[3],&ch[4]); for(i=1;i<=4;i++) { time1[i]=(int)ch[i]; time2[i]=ch[i]-time1[i]; if((i==2 || i==4) && time1[i]<time1[i-1]) time1[i]+=24; } hour=time1[3]-time1[4]+time1[2]-time1[1]; mini=time2[3]-time2[4]+time2[2]-time2[1]; hour=abs(hour+mini*5.0/3.0); hour/=2; if(hour>5) hour=5; printf("%.0lf",hour); } test 3 is wrong. please, read the statement. The time of flights there and back may differ from each other not more than by 10 minutes if answer is one, the time of the first flight is 3 hours and the second - 2 hours 5 minutes... of course, those times differ by 55 minutes... Potomu chto okruglyaetcya do nulya (chisla celye) Kstati ya poluchil AC no u menya bolshaya proga. Kto-nibud mojet obyacnit kak cdelat koroche? [code deleted] Edited by moderator 29.12.2006 09:12 #include <iostream> int main() { int N; std:: cin >> N; /* dynamic memory allocation */ int ** p = new int * [N]; for (int i = 0; i < N; i++) p[i] = new int [N]; /* initialize upper triangle matrix */ p[0][N-1] = 1; int m, n; int ct = 1, value = 2, iter = 1, row = 0, column = N - 2; while (ct <= N - 1) { n = column, m = row; for (int i = 0; i <= iter; i++) { p[m++][n++] = value; value++; }
iter++; ct++; column--; } /* initialize the lower triangle matrix */ row = 1; column = 0, iter = N - 2; while (ct > 1) { n = column, m = row; for (int i = 0; i <= iter; i++) { p[m++][n++] = value; value++; } iter--; ct--; row++; } /* display matrix */ for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) std::cout << p[i][j] << " "; std::cout << std::endl; }
/* release memory */ for (int i = 0; i < N; i++) delete[] p[i]; delete[] p; return 0; } We do not give a fuck. remove the code. first i get acces violation in my code. and then i search what it acces violation, and then i remake my code, then submit again. still get WA #4, before i reamke the code it says Accces Violation in test #4. Can anybody help me? This is my code. #include <iostream> using namespace std; int n,ar[10000],p; int main(){ cin>>n; for (int i=1;i<=n*n;i++){ cin>>p; ar[p]=p; } for (int i=1;i<=n*n;i++){cout<<ar[i]<<' ';} } Edited by author 15.07.2017 10:58 Or I must use Array 2 dimensions? http://ideone.com/8vvdveIf you don't want runtime error #4 pay attention arrays in C/C++ are 0-indexing and enlarge your array by one for example If you want AC you can AC even with one-d array To do that you should write much more smart program than yours understood. thnks dude. Edited by author 15.07.2017 13:05 Edited by author 15.07.2017 13:05 tried all mentioned test cases .all correct. still WA on #12. using surfix array.any idea? code here: #include <cstdio> #include <cstring> int const N=220000; int st[256], rank[2*N], rank1[2*N], count[N], tmp[N]; char a[N], b[N], s[N], max1; int sa[N], height[N], si; int main(){ memset(st, 0, sizeof st); memset(rank, 0, sizeof rank); memset(rank1, 0, sizeof rank1); scanf("%s", b); int n1=strlen(b); for(int i=1; i<=n1; ++i)a[i]=b[i-1]; for(int i=1; i<=n1; ++i)a[i+n1+1]=b[n1-i]; a[0]=' '; a[n1+1]='#'; int n=2*n1+1; a[n+1]='&'; for(int i=1; i<=n; ++i)st[a[i]]=1; for(int i=1; i<=255; ++i)st[i]+=st[i-1]; for(int i=1; i<=n; ++i)rank[i]=st[a[i]];
int k=0; for(int p=1; k!=n; p+=p){ memset(count, 0, sizeof count); for(int i=1; i<=n; ++i)count[rank[i+p]]++; for(int i=1; i<=n; ++i)count[i]+=count[i-1]; for(int i=n; i>=1; --i)tmp[count[rank[i+p]]--]=i;
memset(count, 0, sizeof count); for(int i=1; i<=n; ++i)count[rank[i]]++; for(int i=1; i<=n; ++i)count[i]+=count[i-1]; for(int i=n; i>=1; --i)sa[count[rank[tmp[i]]]--]=tmp[i];
memcpy(rank1, rank, sizeof rank1); rank[sa[1]]=k=1; for(int i=2; i<=n; ++i){ if(rank1[sa[i]]!=rank1[sa[i-1]] or rank1[sa[i]+p]!=rank1[sa[i-1]+p])++k; rank[sa[i]]=k; } } k=0; for(int i=1; i<=n; ++i){ if(rank[i]==1){ k=0; }else{ --k; if(k<0)k=0; while(a[i+k]==a[sa[rank[i]-1]+k])++k; } height[rank[i]]=k; }
int max=-1; for(int i=2; i<=n; ++i){ int p=sa[i]; int q=sa[i-1]; if((p-1)/n1 != (q-1)/n1){ if(p+q+height[i]==n+2){ if(height[i]>max){ max=height[i]; si=p; } } } } for(int i=si; i<si+max; ++i)printf("%c", a[i]); return 0; } THX :) Are interesting in solving the task or in solving the task with suffix array or in knowing why your program outputs wrong at #12? Probably third is the case... So I tried to read your program. Have not understand. Maybe you elaborate details of your algorithm. You need to output the first of them if there are several such strings.But when you correct it ,i guess you 'll WA #18 #include <bits/stdc++.h> #define pb push_back #define fs first #define sc second #define INF (1e9+7) #define forn(i,z,n) for( auto (i) = (z); (i) < (n); ++i) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; struct node { int key; node *left, *right, *parent; node(int q, node *x, node *y, node *p) { key = q; left = x; right = y; parent = p; } }; node *tree = NULL, *f = NULL; void add_n( node *j, node *&z) { if( z == NULL) { z = new node(j->key,NULL,NULL,NULL); return ; } if( z->key >= j->key) { if( z->left) { add_n(j, z->left); } else { z->left = j; j->parent = z; } } else { if( z->right) { add_n(j,z->right); } else { j->parent = z; z->right = j; } } } void show( node *x) { if( x != NULL) { show(x->left); cout << x->key << ' '; show(x->right); } else return ; } node *find_min( node *root) { if( root->left != NULL) { return find_min(root->left); } else { return root; } } void delete_n(node *root, int val ) { if( root == NULL) return ; else if( val < root->key) delete_n( root->left, val); else if( val > root->key) delete_n(root->right, val); else { if( root->left == NULL && root->right ==NULL) { //delete root; root = NULL; } else if( root->left == NULL) { root->right->parent = root->parent; root = root->right; //delete root->right; root->right = NULL; } else if( root->right == NULL) { root->left->parent = root->parent; root = root->left; //delete root->left; root->left = NULL; } else { node *temp = find_min( root->right); temp->parent = root->parent; root = temp; delete_n( root->right, temp->key); } } return ; } void post( node *x) { if( x != NULL) { post(x->right); post(x->left); cout << x->key << ' '; } } void show_parents( node *z) { if(z != NULL) { show_parents(z->left); show_parents(z->right); if( z->parent != NULL) cout << z->key << ' ' << (z->parent->key) << endl; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector <int> v; forn(i,0, n) { int x; cin >> x; v.pb(x); } for(int i = 0; i <n; ++i) { node *help = new node(v[i], NULL, NULL,NULL); add_n( help, tree); } show(tree); // в невозрастающем порядке delete_n(tree, 3); cout << endl; show(tree); return 0; } I have found one mistake and then stopped reading. If val==root key, you are assigning root=NULL. root is a not root of your tree, root is just a copy. So you are assigning NULL to a copy of a node to your tree, not a real node. Ну короче функция которая удаляет, как минимум, должна получать **root вместо *root. Может быть, еще что-то есть, я не дошел. Я как компилятор короче, дооел до первой строки в которой что-то не так и остановился #include<iostream> #include<string> using namespace std; int main () { string s; cin>>s; int max=0,i=0,index=0,a=0,p=0; for (i=0; i<s.size()-5; i++) { if(s[i]>'a' && s[i]<='z') p--; if(s[i]=='S') p+=2; if(s[i+1]=='a') p+=2; if(s[i+1]>='A' && s[i+1]<='Z') p--; if(s[i+2]=='n') p+=2; if(s[i+2]>='A' && s[i+2]<='Z') p--; if(s[i+3]=='d') p+=2; if(s[i+3]>='A' && s[i+3]<='Z') p--; if(s[i+4]=='r') p+=2; if(s[i+4]>='A' && s[i+4]<='Z') p--; if(s[i+5]=='o') p+=2; if(s[i+5]>='A' && s[i+5]<='Z') p--; if (p>max) { max=p; index=i; } p=0; } i=index; if (s[i]!='S' && s[i]>='A' && s[i]<='Z' || s[i]=='s') a+=5; else if (s[i]!='S' && s[i]>='a' && s[i]<='z') a+=10; if (s[i+1]!='a' && s[i+1]>='a' && s[i+1]<='z' || s[i+1]=='A') a+=5; else if (s[i+1]!='a' && s[i+1]>='A' && s[i+1]<='Z') a+=10; if (s[i+2]!='n' && s[i+2]>='a' && s[i+2]<='z' || s[i+2]=='N') a+=5; else if (s[i+2]!='n' && s[i+2]>='A' && s[i+2]<='Z') a+=10; if (s[i+3]!='d' && s[i+3]>='a' && s[i+3]<='z' || s[i+3]=='D') a+=5; else if (s[i+3]!='d' && s[i+3]>='A' && s[i+3]<='Z') a+=10; if (s[i+4]!='r' && s[i+4]>='a' && s[i+4]<='z' || s[i+4]=='R') a+=5; else if (s[i+4]!='r' && s[i+4]>='A' && s[i+4]<='Z') a+=10; if (s[i+5]!='o' && s[i+5]>='a' && s[i+5]<='z' || s[i+5]=='O') a+=5; else if (s[i+5]!='o' && s[i+5]>='A' && s[i+5]<='Z') a+=10; cout<<a<<endl; return 0; } Edited by author 30.12.2014 18:40 Edited by author 03.01.2015 17:13 Edited by author 03.01.2015 17:13 Try Dandro (must be 5, feeling like ur programm returns 10) 1)Look at my solution 7450309 (Runtime error (non-zero exit code) on test 23)) and 7450312(AC). Why i got Runtime error (non-zero exit code) on test 23? In first solution i have nmax=123456 and in second 223456. What is range of n? 2)Look on problem 1974. In forum i wrote test when my AC solution get wrong answer(I can write more tests where my old AC solution falls) I have solved it by reduction to a graph exploration task. Each vertex consists of three parameters (i, j, pr). Where i, j denote number of card at the top of each pile and pr denotes previous state. pr is also a "used" array. So, if pr[N] [N] =none, then impossible. Otherwise just recover answer using pr. You can also have in your state additional parameter diff denotes difference between red and black cards. I have used instead additional two arrays diff11 and diff2 denote difference between first i cards in first pile and in the second pile respectively. There is an edge iff difference at the next step would be not greater than one (abs) , obviously. //I have correct in the IDE, what's wrong? import java.io.IOException; import java.util.Scanner; public class VasyaCare{ public static void main(String[] args) throws IOException { VasyaCare vasya_care = new VasyaCare(); Scanner scn = new Scanner(System.in); int n = scn.nextInt(); try{ // Check if(n < 10){ double[] b = vasya_care.setScore(n); double median = vasya_care.getMedian(b); if(median==3){ System.out.println("None"); } else if(median==5){ System.out.println("Named"); } else if(median >= 4.5){ System.out.println("High"); } else if(median < 4.5){ System.out.println("Common"); } } else throw new IOException("Please, type number from 1 to 10!"); } catch(Exception e){e = new IOException();} } double getMedian(double[] b{ // calculate median score of exam int sum = 0; for(int i = 0; i < b.length; i++){ sum = (int) (sum + b[i]); } return (double)sum/b.length; }
double[] setScore(int n){ // forming list scores Scanner scn = new Scanner(System.in); double[] b = new double[n];{ for(int j = 0; j < n; j++){ int m = scn.nextInt(); if(m<3 || m > 5){ System.out.println("Type score from 3 to 5: "); j--; } else if (m>=3 && m<=5){ b[j] = m; } } } return b; } } // Thank you for your attention! If Vasya has at least one note 3 scholarship is 'None'. So, 355555555... is no scholarship. Sorry if you considered that, I have read your code very careless. You're wrong, sorry, there is my testing: Input Type number exam: 8 Type score: 3 Type score: 5 Type score: 5 Type score: 5 Type score: 5 Type score: 5 Type score: 5 Type score: 5 3.0 5.0 5.0 5.0 5.0 5.0 5.0 5.0 average score: 4.75 Output: High I really don't understand, what's wrong. (( I have just copied code from my Accepted submissions. http://ideone.com/vWEL58I think the problem is easy enough To let post AC code be legal. You have "none" because your case "cur=int (input ()) if cur==3:..." does not check for the average score and passes at runtime immediately. You must check the average score in all cases, not the input variable. Are you a troll? That is Accepted code. If you copy & paste you AC. So there correct answer is "None" and dialog interface is not needed. Moreover, in most cases,there should be no dialog interface to get AC. Let unsigned long long total_cost=0. For every edge E in tree total_cost +=cost_of_all_paths_lies_on_edge(E). double ans=2.0*total_cost/n/(n-1) is overflow and and WA#19. ================ Let double ans = 0. For every edge E in tree ans+=2.0*cost_of_all_paths_lies_on_edge(E)/n/(n-1). That is AC. =========== Maybe if not multiply by two in the first scenario there is also AC, I have not tested. 5 AAAAA ans:5.000 6 CBDCBD ans:3.600 6 DDADDD ans:2.000 They helped me to solve this problem~ Hope they can help you o(∩_∩)o... Test "DDADDD" is really nice. My program shows different results for different shifts of that string. For first two shifts it shows 2.0 and for the next four it shows 1.4,1.8,2.2 and 1.2 respectively 0-1 bfs on graph with 2 * n verticles. Used this idea, but instead I used another adj. list to store directions cin >> u >> v graph[u].push_back(v); direction[u].push_back(0); graph[v].push_back(u); direction[v].push_back(1); 0.046s AC Edited by author 12.07.2017 17:23 how to solve this problem? construct suffix tree for N times and then LCP or there is easier and faster way? Construct suffix tree for each window. Sliding should be at most O(k). Try DP. It's easier to code (+ short) and run much faster than using suffix tree although having the same complexity O(N*K). Could you please decribe me DP solution? Stupid implementation of the hash-table is even easier to code and much easier to invent. Coding is not difficult at all. It seems to be more interesting that there exists O(n + k) solution, isn't it? O(n=4000 + k=1000) would work 0.001ms ;) Hardly. O(n + k) may have arbitrary coefficient. And no one said that solution had been submitted at Timus. And what is the "stupid implementation of the hash-table"? My stupid implementation got TL. Probably DP solution is actually a suffix automation. In suffix automation, we have the following DP. Let X is some state of DAWG. Let DP[X] =1+sum(DP[Y]){there is an edge from X to Y in DAWG}. Then the answer is DP [ROOT] - 1. (Because empty substring not counts) Edited by author 12.07.2017 12:20 AC in 0.109 using only Z-function (also called suffix-function) Z-function is not necessary here, KMP is enough. 0.14 using KMP. Could you explain how to use KMP here? Edited by author 22.02.2014 15:24 Is it possible to solve this problem using suffix automata? I got TL5. But I think that O(N * K) solution have to work faster. Am I wrong? Thanks. PS. Got AC with KMP O(N * K). Edited by author 26.08.2015 00:30 Just got AC with suffix automation. 0.95 sec, 1.5MegaBytes. Nothing tricky, just avoided STL. Construct an automation for every window and find number of different paths. I think my program is pretty slow because when I am constructing an automation I am using modulo operation every step (before adding every new symbol) to deal with cyclic shift. Obviously it can be improved by checking whether i+k>len(s) and branching. Also my program is slow because I am allocating and deallocating an entire array for DAWG for every window. Obviously it can be allocated once //#define LOCAL #include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXN 250000+10 int N; char str1[MAXN], str2[MAXN]; char temp[MAXN*2]; int kmp(char* s, char* t, int pos); void get_next(char* t, int* next, int t_len); int main() { #ifdef LOCAL freopen("1423_String_Tale_2.in", "r", stdin); freopen("1423_String_Tale_2.out", "w", stdout); #endif scanf("%d", &N); scanf("%s%s", str1, str2);
int s1_len = strlen(str1); int s2_len = strlen(str2);
if(s1_len != s2_len){ printf("%d\n", -1); return 0; }
strcpy(temp, str1); strcat(temp, str1); int ans; ans = kmp(temp, str2, 0); if(ans != 0 && ans != -1) printf("%d\n", s1_len-ans); else printf("%d\n", ans); return 0; } int kmp(char* s, char* t, int pos) { int s_len = strlen(s); if(pos<0 || pos>s_len-1){ fprintf(stderr, "%s", "Error: invalid pos."); system("pause"); }
int t_len = strlen(t); int *next = (int*)malloc(sizeof(int) * t_len); get_next(t, next, t_len);
int i = pos; int j = 0; while(i<s_len && j<t_len){ if(j<0 || s[i]==t[j]){ i++; j++; } else j = next[j]; }
// free(next); if(j >= t_len) return i-t_len; else return -1; } void get_next(char* t, int* next, int t_len) { next[0] = -1; int j = 0; int k = -1; while(j < t_len){ if(k==-1 || t[j]==t[k]){ j++; k++; next[j] = k; } else k = next[k]; } } ############################################### Can anyone tell me WHY??? Edited by author 11.07.2017 19:31 Maybe you don't process characters with negative ASCII correctly. I don't know how standard string functions deal with negative ASCII. |
|