Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Задача решается "в лоб" | Mahilewets | 1007. Code Words | 19 Jul 2017 00:52 | 1 | Просто по длине слова определяем, какой у нас случай. (Замена, удаление или вставка). Затем для каждой позиции пытаемся внести изменения и смотрим, получается у нас выполнение условия или нет. Удобно завести массив постфиксных сумм для того чтобы быстро пересчитать сумму позиций единиц. | | Надоело писать на чужом языке. Решение на русском. | Mahilewets | 1247. Check a Sequence | 18 Jul 2017 22:28 | 1 | Так как сумма всех элементов последовательности равна (S+N), то сумма всех элементов последовательности, в которой каждый элемент уменьшен на единицу, равна просто N. Тогда если мы найдём в такой последовательности с уменьшенными членами отрезок с максимальной суммой и сравним сумму на нем с числом N, то мы узнаем ответ на задачу. А именно, если эта сумма превосходит N, то ответ "NO". В противном случае, ответ "YES". Отрезок с максимальной суммой ищется за O(n) методом кумулятивных сумм. | | WA 1 | Raman Gupta | 1658. Sum of Digits | 18 Jul 2017 18:40 | 4 | WA 1 Raman Gupta 3 Dec 2012 19:49 All the test cases given in this forum are working.But giving WA 1 my code is: #include <stdio.h> #include <string.h> int len[910][8110]; int dig[910][8110]; int num[110]; int main(){ int t,s1,s2,k,pt,i,j,l,temp; memset(len,0,sizeof(len)); for(i=1;i<=900;i++){ for(j=1;j<=8100;j++){ for(k=1;k<=9;k++){ if((i-k)<0||(j-k*k)<0) break; else if((i-k)==0&&(j-k*k)==0){ len[i][j] = 1; dig[i][j] = k; } else if(len[i-k][j-k*k]>0){ if(len[i-k][j-k*k]+1<len[i][j]||len[i][j]==0){ len[i][j] = len[i-k][j-k*k]+1; dig[i][j] = k; } } else continue; } } } scanf("%d",&t); while(t--){ scanf("%d %d",&s1,&s2); pt = 0; if(len[s1][s2]==0||len[s1][s2]>100) printf("No Solution"); else{ i=s1; j=s2; while((len[i][j]>=1)&&i>=1&&j>=1){ l = dig[i][j]; num[pt++] = l; i = i-l; l = l*l; j-=l; } for(i=0;i<pt;i++){ for(j=i+1;j<pt;j++){ if(num[i]>num[j]){ temp=num[i]; num[i]=num[j]; num[j] = temp; } } } for(i=0;i<pt;i++) printf("%d",num[i]); } printf("\n"); } return 0; } Your mistake is here: if(len[i-k][j-k*k]+1<len[i][j]||len[i][j]==0){ len[i][j] = len[i-k][j-k*k]+1; dig[i][j] = k; } length might be the same but the value might be smaller. You just check the length. I am able to see experimentally that length really might be the same while the values differ I can't understand why it so I feel that it can't be truth "S" in "Solution" shouldn't be capital :P | | The only possible difficulty. | Mahilewets | 1072. Routing | 17 Jul 2017 23:37 | 1 | To read IP address /subnet mask I recommend you to use the following template unsigned int read_mask(){ unsigned int a, b, c, d; scanf("%u.%u.%u.%u", &a, &b, &c, &d); return (a<<24) + (b<<16) + (c<<8) + d; } | | INCREDIBLE easy problem. | Mahilewets | 1160. Network | 17 Jul 2017 21:22 | 3 | You can just sort edges in non-increasing order and add them sequentially until there are two or more connectivity components... It is absolutely of no importance How many edges are used Only the size if the largest edge matters I DON'T KNOW why the problem rating is not 80, but 300. Don't say things like There you need DSU Anansi's Cobweb requires DSU And it is only 170 rating points | | WA #2 | YuFeng | 1451. Beerhouse Tale | 17 Jul 2017 19:44 | 2 | WA #2 YuFeng 17 Jul 2017 19:41 I don't know the test I know exactly Because I have verified it myself That ternary search gives a solution Even C float type is enough And something about 200 iterations in each loop | | 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 | Mahilewets | 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 | Anton_Blick[SESC] | 1720. Summit Online Judge | 17 Jul 2017 11:20 | 1 | | | Possible solution. | Mahilewets | 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 | Mahilewets | 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. | Mahilewets | 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? | ILYA | 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 :) 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 |
|
|