Common Board| Show all threads Hide all threads Show all messages Hide all messages | | No subject | YuFeng | 1451. Beerhouse Tale | 17 Jul 2017 19:38 | 1 | Edited by author 17.07.2017 19:41 | | It took pretty long time | Nikita Mogilevets | 1523. K-inversions | 17 Jul 2017 16:52 | 1 | It was hard to understand how to calculate the answer. It is relatively easy to invent a correct solution when you know the expected time complexity. Solve the task online, read elements one by one. So, you have dp[i][j] = count of different j-inversions ending at element number j. dp[i] [j] =sum (dp[p] [j-1]) for all p>i. The answer is sum(dp[i] [k]) for all i=0...n-1. As mentioned below, an array of Fenwick trees is your friend. | | notice: | Shen Yang | 1365. Testing Calculator | 17 Jul 2017 13:06 | 1 | notice: Shen Yang 17 Jul 2017 13:06 x/0==0 re many times, there is nothing in problem description... | | Don't understand why it's so difficult | gepto | 1720. Summit Online Judge | 17 Jul 2017 11:20 | 1 | | | Possible solution. | Nikita Mogilevets | 1298. Knight | 17 Jul 2017 01:28 | 1 | You can have an array deg[i][j] = count of adjacent unvisited cells for cell (i;j). While doing DFS sort edges by non-decreasing deg[i+move. first] [j+move. second]. It calls an heuristic after some scientist whose name begins at W. | | what is the difference between this code and that code, still get wrong | VNeo | 1110. Power | 16 Jul 2017 18:32 | 11 | i got WA#6 when i use this code #include <iostream> #include <cmath> using namespace std; long int n,m,y,p,q,r[999]; int main(){ cin>>n>>m>>y; for (int i=0;i<m;i++){ if (lround(pow(i,n)) % m==y){ q++; r[q]=i; } } if (q==0){ cout<<"-1"; } else { for (int i=1;i<=q;i++){ cout<<r[i]<<' '; } } } but when i use neighbored code which is already acc, and tested some test case between them, it give me same results. whats probably wrong in my code by the way, the neighbored code is pascal language, but the point is, i just used that for test case. oh , i forgot. The neighbored code is this var ans: array[1..1000] of longint; n,m,y,q,i: longint; function BinPow(x,y: longint): longint; begin if y=1 then BinPow:=x else if y mod 2=0 then BinPow:=sqr(BinPow(x,y div 2)) mod M else BinPow:=(sqr(BinPow(x,y div 2))*x) mod M; end; begin readln(n,m,y); q:=0; for i:=0 to m-1 do begin if BinPow(i,n)=y then begin inc(q); ans[q]:=i; end; end; for i:=1 to q do write(ans[i],' '); if q=0 then writeln(-1); end. netman from timus judge, sorry for copied your code. Look at the limitations. You can have X^N=998^998. That is 9,98e1000. Look at fundamental data types range. double is something like not greater (-1e309;1e309) with 15 digits after point . That is much smaller than you need. So, in function pow there is an overflow. That means double LOSES PRECISION. And if actually X^N mod M == Y for some big X^N them your program can't see it. Because last digits of X^N are lost due to an overflow. And in netman's code, there is such a function, that keeps ONLY the last digits. So, the main difference is. Your code keeps MOST significant digits. netman's code keeps LEAST significant digits. More precisely, netman's code keeps last approximately log10(M) +1 digits. That is, if the number is say 12345...{lot of digits}... 6789 Then your code keeps 1234 as digits and keeps additional information only about HOW MANY digits are before 1234. And netman's code keeps only digits 6789. so, what i've gonna do?. I still cant find the solution. is there are any function like pow, but can keep LEAST significants digits like you said before? still get WA#6, after change lround into llround. but why?, llround is the function that round nearest decimal into long long integer. it much more greater than lround. What is maximal long long? something like 1e20. It is so SMALL against 998^998. int pow(int X, int N, int M) { if(N<1) return 1; int res=pow(X, N>>1, M); res=(res*res)%M; if(N&1) return (X*res)%M; return res; } I got AC right now with this power function. | | You can mix Aho-Corasick and DFS to get very fast solution | Nikita Mogilevets | 1603. Erudite | 15 Jul 2017 22:44 | 1 | Though without Aho-Corasick and without trie and without any optimizations simply DFS with used [i] [j] and backtracking is fast | | No subject | nurbolat96 | 2078. Bowling game | 15 Jul 2017 22:44 | 5 | 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. | | I have AC. I am interested in another method of solution. | Nikita Mogilevets | 1164. Fillword | 15 Jul 2017 21:56 | 3 | 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 | | RE #10 with recursion alg!!! | YuFeng | 1394. Ships. Version 2 | 15 Jul 2017 19:45 | 1 | #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 | | Who give me some tests? | Mirraz | 1070. Local Time | 15 Jul 2017 18:00 | 9 | 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 | | Accepted in c++ | WENXIANG LU | 1319. Hotel | 15 Jul 2017 13:53 | 3 | #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. | | Acces Violation test #4 and after that get WA #4, C++. Anyone can help me? still stuck test #4 | VNeo | 1313. Some Words about Sport | 15 Jul 2017 13:03 | 4 | 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 | | WA#12 | jerry | 1297. Palindrome | 15 Jul 2017 12:31 | 3 | WA#12 jerry 15 Jul 2017 07:25 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 :) Re: WA#12 Nikita Mogilevets 15 Jul 2017 09:29 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 | | Sasuke failed? | Nikita Mogilevets | 1000. A+B Problem | 15 Jul 2017 11:00 | 1 | | | Двоичное дерево поиска: не могу найти ошибку в функции, которая удаляет вершину. Помогите пожалуйста. | Syavaprd | | 15 Jul 2017 08:59 | 4 | #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. Может быть, еще что-то есть, я не дошел. Я как компилятор короче, дооел до первой строки в которой что-то не так и остановился | | WA#19 can you help me? | Sorn | 1786. Sandro's Biography | 15 Jul 2017 02:42 | 2 | #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) | | To admins | __Andrewy__ | 1743. Domino Sorting | 14 Jul 2017 14:10 | 1 | 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) | | How to solve. | Nikita Mogilevets | 1501. Sense of Beauty | 14 Jul 2017 10:39 | 1 | 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. | | Why i get "Wrong answer"? | Sagamore | 2056. Scholarship | 13 Jul 2017 10:41 | 7 | //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. |
|
|