Common Board| Show all threads Hide all threads Show all messages Hide all messages | | help me, find mistake, 5 test | Dmitry Vaskin`~ | 1991. The battle near the swamp | 13 Nov 2018 21:04 | 1 | #include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); int n,k; cin >> n >> k; int dontused=0,dontdie=0; int f; for(int i=0;i<n;i++) { cin >> f; if(k>f) { dontdie+=k-f; } if(k<f) { dontused+=f-k; } } cout << dontused << " " << dontdie; return 0; } | | Getting TLE | Rabib Ahmad | 1086. Cryptography | 13 Nov 2018 01:46 | 2 | What is the problem with my code? #include <iostream> using namespace std; #include <cmath> bool check_prime(double n) { int c; for (c=2;c<= sqrt(n);c++) { if((int) n%c==0) return 0; } if(c==(int) n) return 1; } int nth_prime(int n){ int m=1; while (n>0) { m++; if (m == 2) { n--; } if (m%2!=0) { if (check_prime(m)==1) { n--; } } } return m;
} int main() { int n,m,i,a[15000],s; scanf("%d",&n); for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(i=0;i<n;i++){ s = nth_prime(a[i]); printf("%d\n",s); } return 0; } | | Why it is wrong? | иван | 1567. SMS-spam | 12 Nov 2018 21:22 | 1 | a=input() c=0 c+=a.count('a') c+=a.count('d') c+=a.count('g') c+=a.count('j') c+=a.count('m') c+=a.count('p') c+=a.count('s') c+=a.count('v') c+=a.count('y') c+=a.count('y') c+=a.count('.') c+=a.count(' ') c+=a.count('b')*2 c+=a.count('e')*2 c+=a.count('h')*2 c+=a.count('k')*2 c+=a.count('n')*2 c+=a.count('q')*2 c+=a.count('t')*2 c+=a.count('w')*2 c+=a.count('z')*2 c+=a.count(',')*2 c+=a.count('c')*3 c+=a.count('f')*3 c+=a.count('i')*3 c+=a.count('l')*3 c+=a.count('o')*3 c+=a.count('r')*3 c+=a.count('u')*3 c+=a.count('x')*3 c+=a.count('!')*3 print(c) | | WA 20 With Dijkstra. What to do? | Kogut Ivan'` | 1871. Seismic Waves | 12 Nov 2018 18:27 | 1 | I can't understand problem in my algorithm. Can it be solved with just Dijkstra? | | How to slove it?? Any hints? | Algorithm | 1260. Nudnik Photographer | 12 Nov 2018 11:39 | 25 | let A[i][j] be the number of i permutations that start with j and we jump 2. The recurrence is: a[i][1] = a[i - 1][1] + a[i - 1][2], a[i][2] = a[i - 1][2] + a[i - 3][2] I use the same methon...But I got Wa???? We can do it more easyly! Just think of this: 1 2 ... means N - 1; 1 3 2 4 means N - 3; 1 3 5 7...6 4 2 only 1; 1 3 4 2 (only N == 4); So we can DP; You can using this: Initilization: a[1]:=1; a[2]:=1; a[3]:=2; And solve: a[i]:=a[i-1]+a[i-3]+1; So, your answer in a[n] I konw why I was WA...... Very thanks!!!! Well, actually I decovered this formula after writing brute force algorithm. I am wondering how it could be proven. Any ideas? Edited by author 10.04.2004 02:04 But Timgreen had almost proved it. write the permutations down and look it carefully as hard as you can and you'll find out sth useful for you associated with the informations provided above by all the upper friends... Can somebody give tests? for exmaple for 6,10,55... Thanks. for 6 , ans = 9 for 10, ans = 46 for 55, ans = 1388937263 I don't understand your formula . Could you explain ? Take i=5 for example The permutations are: 1 2 3 4 5 1 2 3 5 4 1 2 4 3 5 1 2 4 5 3 1 3 2 4 5 1 3 5 4 2 a[i-1] stands for the first four, beginning with '1 2'. If you ignore 1, you have the same prob for N=i-1. a[i-3] stands for the fifth, beginning with '1 3 2 4'. If you ignore 1, 3, 2, you have the same prob for N=i-3. And a special case (the last) -- all the odds in increasing order, followed by all the evens in decreasing order. The is what the +1 in the formula means. Good luck! I used another method to solve this. Suppose we have N numbers. We will care about five possible configurations: K(n) ... n n-1 ... T(n) ... n-1 n ... E(n) ... n-2 n P(n) ... n n-1 S(n) ... n-1 n here K(n) is the number of correct configurations of the first type and so on. It's clear that the answer for N will be K(N)+T(N)+E(N)+P(N)+S(N). So, what we need to do is understand how to get K(n+1),T(n+1)... from K(n),T(n),... And it is very easy to see that following is true: K(n+1) = T(n) T(n+1) = K(n)+P(n) E(n+1) = P(n) P(n+1) = S(n) S(n+1) = S(n)+E(n) I don't know if we can call this a proof. This is an observation I guess. Take i=5 for example The permutations are: 1 2 3 4 5 1 2 3 5 4 1 2 4 3 5 1 2 4 5 3 1 3 2 4 5 1 3 5 4 2 a[i-1] stands for the first four, beginning with '1 2'. If you ignore 1, you have the same prob for N=i-1. a[i-3] stands for the fifth, beginning with '1 3 2 4'. If you ignore 1, 3, 2, you have the same prob for N=i-3. And a special case (the last) -- all the odds in increasing order, followed by all the evens in decreasing order. The is what the +1 in the formula means. Good luck! My idea is : (a bit complicated) definition : dp[x][0][0] = [...] , x , x-1 , [...] dp[x][0][0] = [...] , x-1 , x-1 , [...] dp[x][1][0] = [...] , x , x-1 dp[x][1][0] = [...] , x-1 , x dp[x][1][0] = [...] , x-2 , x (dp[x][i][j] is number of sequences satisfying the corresponding rule) recurrence : dp[i][0][0] = dp[i-1][0][1]; dp[i][0][1] = dp[i-1][0][0] + dp[i-1][1][0]; dp[i][1][0] = dp[i-1][1][1]; dp[i][1][1] = dp[i-1][1][1] + dp[i-1][1][2]; dp[i][1][2] = dp[i-1][1][0]; answer (to be printed is) : dp[n][0][0] + dp[n][0][1] + dp[n][1][0] + dp[n][1][1] + dp[n][1][2] proof : left for you :) Edited by author 02.05.2013 19:18 I have observed the answers.I found that a[i]=a[i-1]+a[i-2]-a[i-5]; I still don't know why! Above has been shown: a[i] = a[i-1] + a[i-3] + 1 this holds for each i, then also: a[i-2] = a[i-3] + a[i-5] + 1 So a[i-2] - a[i-3] - a[i-5] = 1 and (substitute this result in the first equation) a[i] = a[i-1] + a[i-3] + a[i-2] - a[i-3] - a[i-5] which reduces to a[i] = a[i-1] + a[i-2] - a[i-5] Can you explain your formul?how should I use it!) cool, note that we can unite 3rd and 4th cases as one case when n >= 4. my formula is: a[i][1] = a[i-1][1] + a[i-2][2] a[i][2] = a[i-2][1] + 1 But i don't understand your formula? Could you explain?? Edited by author 14.07.2008 22:25 I've solved it with help of asympthotic. Starting from 20 - 25-th member (it can be found recursively) - a[i] ~ a[i-1]*(a[i-1]/a[i-2]) I use dfs to find the regular for some test n = 1 2 3 4 5 6 7 8 9 10 11 ans= 1 2 2 4 6 9 14 21 31 46 68 then I found f[n] = f[n-1] + f[n-2] - f[n-5] then I got AC. | | why wrong answer on test case #2 ? | Al - Amin Hosen | 1068. Sum | 11 Nov 2018 23:56 | 3 | #include<stdio.h> int main() { int n, sum=0, i; scanf("%d", &n); if(n>0) { for(i=1; i<=n; i++) sum=sum+i; } else if(n<0) { for(i=n; i<=1; i++) sum=sum+i; } printf("%d", sum); return 0; } | | Actually it just describes Euclid algorithm in a tedious way. | some_programming_novice | 1053. Pinocchio | 11 Nov 2018 10:21 | 1 | | | здавствуйте! | dainil | 1264. Workdays | 11 Nov 2018 00:24 | 1 | помогите понять условие, пожалуйста, буду благодарен | | Why this is said "wrong" ? this is true. | Sadriddin | 1209. 1, 10, 100, 1000... | 10 Nov 2018 22:37 | 1 | #include <iostream> #include <math.h> using namespace std; int main() { int n,k,i,a;float z; cin>>n; int *b; b=new int [n]; for(i=1;i<=n;i++){cin>>k;z=sqrt((k-1)*8+1);a=z;if(a==z)b[i-1]=1;else b[i-1]=0;} for(i=1;i<=n;i++)cout <<b[i-1]<<" "; return 0; } | | хммм, что не то? what??? | dainil | 1001. Reverse Root | 10 Nov 2018 00:35 | 1 | import math a=input().split() for i in range(len(a)): u=int(a[i]) l=str(math.sqrt(u))+'0000' for x in range(len(l)): if l[x]=='.': print(l[0:x+5]) Edited by author 10.11.2018 00:35 | | oddiygina kichik harflarning ixtiyoriy ravishda to'ldirsangiz kifoya!!!! | Adhambek | 1219. Symbolic Sequence | 9 Nov 2018 15:52 | 2 | Buning uchun rand() funksiyasidan foydalaning. masalan: 1000000 ta ababababbabab.....asdbasdsajkdbksajbdjkasbdkjbskfjbaksjdbfkjsad. faqat ixtiyoriy ravishda bo'lsin k = rand()%26 + 97 ; qilib chiqaring shuni uzi kifoya Edited by author 15.06.2013 11:32 | | Python Wrong answer. Первый раз на этом сайте. Что не правильно? | Altynbek | 1001. Reverse Root | 9 Nov 2018 15:00 | 2 | intxt = input() for i in intxt.split()[::-1]: print('%.4f' % int(i) ** 0.5) IIRC, Python's input() reads only one line. You should probably do this for every line in sys.stdin. Well, rarely do I write solutions in Python so I might be wrong. | | For C++ Users | 0blivium | 1161. Stripies | 9 Nov 2018 03:58 | 1 | Use the priority queue data structure. | | WA #5, WA #6 | 👨🏻💻 Spatarel Dan Constantin | 2096. All Inclusive | 9 Nov 2018 01:22 | 1 | input: 3 3 1 1 1 0 0 2 1 3 1 2 1 1 1 3 0 0 0 1 2 1 0 0 output: - - 1 | | Runtime Error(access Violtion) HELP!! | Hrant Nurijanyan [RAU] | 1370. Magician | 8 Nov 2018 13:03 | 5 | #include <iostream> #include <string> using namespace std; int main() { string a[3000]; int n; int m; cin >> n; cin >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } int j = m; for (int i = 0; i < 10; i++) { cout << a[j]; j++; if (j == n ) { j = 0; } } cout << endl; return 0; } add ""cout<<flush;"" in diffrent places and see if it works(sometimes solves the error) string a[3000]; Hmm. It's really funny to use string array for containing int values. Edited by author 13.04.2014 14:08 1 ≤ M ≤ 32767. and you are trying to print a[j] which j >= m m can be above n; m can be above a length. To put big arrays on stack is a bad idea. a should be dynamic array or vector. | | WHY WA3??? PLEASE HELP!!!! | Furious Wolf | 1370. Magician | 7 Nov 2018 19:49 | 12 | I THINK THAT MY PROGRAM MUST HAVE AC BUT WA3 WHAT THE 3 TEST???? PLEASE POST TEST №3!!!!!!! Edited by author 13.05.2007 15:12 blonde :) ha ha. It is joke about WRITING MESSAGES WITH CAPS LOCK ON Which difference write messages WITH CAPS LOCK ON or with caps lock off? Please post some tests! I dont know why my program had WA :( 12 335 1 2 3 4 5 6 7 8 9 0 7 7 answer 7123456789 Thanks Furious Wolf 13 May 2007 15:06 Thanks for the test, I've got AC! #include <iostream> #include <algorithm> using namespace std; int main() { int i,n,m; cin>>n>>m; long int *a=new long int [n]; for(i=0;i<n;i++) cin>>a[i]; rotate(a,a+m,a+n); long int b[10]; for(i=0;i<10;i++) b[i]=a[i]; for(i=0;i<10;i++) cout<<b[i]; cout<<endl; return 0; } the test of Alias doesn't work,but why?What is incorrect in code? Already got AC....this code is right,you only need to decrease the quantity of ranges by decreasing the "m".......make m<n and everything will be ok ;) Or you can use "%" :) And yes,i'm necroposter ))) | | easy solution for python | Yucheng | 1567. SMS-spam | 4 Nov 2018 08:37 | 1 | dic={'a':1,'d':1,'g':1,'j':1,'m':1,'p':1,'s':1,'v':1,'y':1,'.':1,' ':1, 'b':2,'e':2,'h':2,'k':2,'n':2,'q':2,'t':2,'w':2,'z':2,',':2, 'c':3,'f':3,'i':3,'l':3,'o':3,'r':3,'u':3,'x':3,'!':3} m=input() total=0 for i in range(len(m)): total+=dic[m[i]] print(total) | | easy solution for python | Yucheng | 1083. Factorials!!! | 3 Nov 2018 20:50 | 1 | a,b=input().split() n=int(a) k=len(b) temp=n t=k while temp-k>0: n*=(temp-k) k+=t print("%d"%n) | | AC with long double | Shen Yang | 1594. Aztec Treasure | 2 Nov 2018 19:23 | 7 | deleted Edited by author 21.10.2017 21:07 Why not std:: complex? I have not read the code very carefully, maybe miss something important Maybe not possible to made it long double? it involves with Chebyshev polynomial U(x) is Chebyshev polynomial Um(i*An/2)= i*An*Um-1(i*An/2)-Um-2(i*An/2) i is unit imaginary number An is a n*n matrix Aij==1 if and only if abs(i-j)==1. sqrt(det(Um(i*An/2)) is the answer.. I use long double because I need to judge the sign of sqrt(ans^2) Edited by author 21.10.2017 09:46 Delete the code please. Posting AC code here violates the rules. You can explain your idea (which is not recommended either) 100 100 exactly result: 211296849512315762188619578574048657110653043609449472144725843973442479614058285996396387014570402447830177110492225916018306620473309898122553032154580078102848452707439935767561964432764309438889871659414420572001206784720890894593722611533746574726650832697664485530063095995962974740556608440361525520881534009295321784945692404915331234788462418215336479515406547891566477310928856298254153861327506039317299734093964771367687300616477954739907701770903890588939771176356807995358624375906635501695115399580918628783125903772434369374398388373031207325810190683145008704318854255120274024753774893652675256050843161415941752800234892558301824773136514256893938068687029095739098286424428752900415743287209790876036884080292271611832363684077924978489349099638343563775430445274281910983984807471952213028600596500243377496299053827784481766322799764412944529657092342282080566012889979741375614523723377108743228485047911163027695369684514018557778209543315449702696764786683247792132799136211383970764610828007749277178715661259454260357449248458683734007683846942145977953891807183259007702385978401831386444472112720952063414073905105738447216839800171442748174691808886777635485410113868685679678838952355104065272999262338505349001538065924096 | | No subject | 🦄imosk72🦄[GTGU] | 1422. Fireflies | 2 Nov 2018 18:55 | 1 | i think test set is not full. my AC soulution uses floating arithmetic and does not work correctly on tests like 3 0 0 0 1 1 1 100000 100000 99999 right answer should be 2? |
|
|