Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Accepted sqrt_decom && binary_search && quick sort 0.765 | Temirbay Miras | 1613. For Fans of Statistics | 12 Feb 2015 10:15 | 1 | | | WA3 | zimpha | 2041. Nanomatryoshkas | 12 Feb 2015 07:35 | 1 | WA3 zimpha 12 Feb 2015 07:35 can anyone provides some testcases? | | Just use brute force, it works. | gopher nice byte | 1005. Stone Pile | 12 Feb 2015 03:36 | 1 | | | FUNNY SOLUTION (VIEWER DISCRETION IS ADVISED) | cena | 1044. Lucky Tickets. Easy! | 11 Feb 2015 23:52 | 3 | #include <iostream> using namespace std; int main() { int arr[4] = {10, 670, 55252, 4816030}; short m; cin >> m; cout << arr[m / 2 - 1]; return 0; } //hey; can you guess how i got these values?(think of the simplest solution) Edited by author 15.02.2013 04:31 if we are not too creative to calculate this on paper and there is no forum to take solution just do backtracking it works fine 1 second and something #include <iostream> using namespace std; int x[10], n, cont = 0; void back(int k) { if(k == n) { int s1 = 0, s2 = 0; for(int i = 0; i < n / 2; i++) { s1 += x[i]; } for(int i = n / 2; i <= n; i++) { s2 += x[i]; } if(s2 == s1) cont++; } else for(int i = 0; i <= 9; i++) { x[k] = i; back(k + 1); } } int main () { cin >> n; back(0); cout << cont; return 0; } | | TLE on #8 | Shervin | 1423. String Tale | 11 Feb 2015 09:24 | 1 | I'm using KMP I don't know why I get TLE? #include <iostream> int main(int argc, const char * argv[]) { long long int NumofChars; long long int finAns=-1;
scanf("%lld",&NumofChars);
char lettersS[2*NumofChars]; char lettersT[NumofChars]; char letter_tmp;
for (long long int i=0;i<NumofChars;i++) { scanf(" %c",&letter_tmp); lettersT[i]=letter_tmp; }
for (long long int i=0;i<NumofChars;i++) { scanf(" %c",&letter_tmp); lettersS[i]=letter_tmp; lettersS[i+NumofChars]=letter_tmp; }
long long int prefix[NumofChars]; prefix[0]=0; prefix[1]=0;
long long int pi=0; long long int pj=1;
while(pj<NumofChars-1) { if(lettersT[pi]==lettersT[pj]) { prefix[pj+1]=prefix[pj]+1; pi++; pj++;
} else {
pi=0; if(lettersT[pi]==lettersT[pj]) { prefix[pj+1]=1; pi++; pj++;
} else { prefix[pj+1]=0; pj++;
}
} }
finAns=-1;
long long int i=0; while(i<NumofChars) {
long long int Matchcount=0; long long int j_init=0; for (long long int j=j_init;j<NumofChars;j++) { if(lettersS[i+j]==lettersT[j]) { Matchcount++; } else { if(j-prefix[j]>0) { i=i+j-prefix[j]; j_init=prefix[j];
} else { i++; }
break; } }
if(Matchcount==NumofChars) { finAns=i;
break; } } std::cout<<finAns; return 0; } | | Don't cook steaks like that! | alextj | 1820. Ural Steaks | 11 Feb 2015 01:34 | 1 | Whoever thought of this problem haven't fried steaks in real life. The only way to get an acceptable solution to 1820 is to cook the steaks somewhat similar to this order: Minute 1: St1A, St2A Minute 2: St1B, St3A Minute 3: St2B, St3B (where there are three steaks: St1, St2 and St3, and each having side A and side B). The problem with this is: After St2A side is cooked, it will be taken off the heat and cool down for one minute before cooking the other side, thus in the end the steak will be less cooked than stake 1 and 3. That's all sorts of wrong, you'll be ruining a good steak! :-D | | TLE | Petru Trimbitas | 1846. GCD 2010 | 10 Feb 2015 20:23 | 2 | TLE Petru Trimbitas 3 Dec 2011 21:33 For those who get TLE #17 try to use scanf/printf instead of cin/cout Thank you Petru, your advice helped me to pass from TLE 17 to TLE 29 :) | | Why if n=4, the answer is 204 | plague | 1586. Threeprime Numbers | 9 Feb 2015 19:41 | 3 | Explain me please, why if n=4, the answer is 204. I get 2513. 1031 is not a THREE-PRIME nummber. 103 is THREE-PRIME nummber, but 031 isn't, it's TWO-PRIME number Thank you for question and answers. It help to understand the task. | | WA#5 CLOSED | dingo | 1306. Sequence Median | 9 Feb 2015 19:17 | 2 | Here is my code: ----- [The code was here] ----- I've got the point. Thank you. Edited by author 17.07.2011 18:48 | | RE - #14..(c++). because of map<string,int>? | OIdiot | 1837. Isenbaev's Number | 9 Feb 2015 07:13 | 2 | /* Machine: Class4_B2 System: Windows7 SP1 32bit */ [code deleted] Edited by moderator 19.11.2019 23:15 My bad.. I thought it only contains 100 names, but 300 in fact. | | different between undefined and 3 | amirshir | 1837. Isenbaev's Number | 9 Feb 2015 06:59 | 2 | what's different between undefined and 3? can you help me? Isenbaev -> a -> b -> c. In this chain, a is 1, b is 2 and c is 3. Obviously,there is a path from Isenbaev to c. But In this situation: Isenbaev -> a -> b. c. c isn't a teammate of anyone who is connected with Isenbaev. So, c is 'undefined'. | | WA#2 | LNCP | 1132. Square Root | 8 Feb 2015 09:54 | 2 | WA#2 LNCP 8 Feb 2015 09:50 I use Tonelli-Shanks algo,but i got WA#2.By now I had read all te topic but hadn't found the error.Please give me some hints or cases. the key code: int inverse(int a, int m)//thr inverse element of a(modulo m); int quickpower(int a, int n, int m)//a^n(modulo m); void sqrt(int a, int p) { if(p==2) { cout << 1 << endl; return; } if(quickpower(a,(p-1)/2,p)!=1) { cout << "No root" << endl; return; } int s, t = 0, b = 0, i, j, x, y, inv, N; for (s = p - 1; !(s & 1); s /= 2) t++; inv = inverse(a, p); x = quickpower(a, (s + 1) / 2, p); for (N = 2; quickpower(N, (p - 1) / 2, p) == 1; N++); for (i = t - 2; i >= 0; i--) { b = b ? b*b%p : quickpower(N, s, p); y = x*x%p*inv%p; for (j = 1; j <= i; j++) y = y*y%p; if (y != 1) (x *= b) /= p; } if (2 * x < p) cout << x << " " << p - x << endl; else cout << p - x << " " << x << endl; return; } I had got AC now.Really a small mistake! | | Runtime Error 1003 Parity | Sunny | 1003. Parity | 8 Feb 2015 09:10 | 1 | Deleting this post... had to hack another solution. Still don't see what was wrong with the original approach... must have been some kind of parsing issue with the input. Edited by author 08.02.2015 09:36 | | test 16 is terribly! HELP!!!!!! | Vasya | 1286. Starship Travel | 7 Feb 2015 20:48 | 5 | I am sure that my program is right, but i get WA on test 16. Do somebody know this test or can say something interesting? I think, you haven't really proved your algorithm. I guess it's much more interesting than just gcd. Sergei Try using long long and read your data like this scanf( "%I64d%I64d%I64d%I64d%I64d%I64d", &p, &q, &sx, &sy, &ex, &ey ); Thanks for all, if not you I die near my PC. | | Loop in python | crc | 1013. K-based Numbers. Version 3 | 7 Feb 2015 18:55 | 2 | a "for"-loop in python for integers 1 <= i <= 10^18 needs a lot of time. Is there a way to avoid to do such a huge for-loop? Edited by author 21.01.2015 20:28 You should calculate recurrence with Matrix and use quick-power to calculate the power of Matrix.Do you need details about the algo? | | wa 5 | ziwert | 1607. Taxi | 7 Feb 2015 17:20 | 4 | wa 5 ziwert 21 Sep 2010 01:12 hi everybody! i have wa 5 but i don't understand my mistake. can anybody who knows some tests help me? Re: wa 5 Bahodir | {TUIT} | 29 Nov 2014 17:21 | | You are required to be just very attentive to solve this problem | Evgeniy[VVV] | 1804. The Machinegunners in a Playoff | 7 Feb 2015 17:16 | 1 | | | Помогите time limit wa8 | NikolosAvr | 1196. History Exam | 6 Feb 2015 20:26 | 2 | #include <iostream> int main() { long int i, n, m, z, s, k, a[16000], l, r, mid; std::cin >> n; k=0; for (i=0; i<n; i++) { std::cin >> z; if ((i!=0) && (z!=a[k])) { a[k]=z; k++; } if (i==0) { a[k]=z; k++; } } n=k-1; std::cin >> m; s=0; k=0; for (i=0; i<m; i++) { l=0; r=n; k=0; std::cin >> z; if ((z>a[0]) && (z<a[n])) while ((l<r) && (k<n-1)) { k=k+1; mid=(l+r)/2; if (a[mid]>z) r=mid; else if (a[mid]<z) l=mid; else if (a[mid]==z) break; } else if ((z==a[0]) || (z==a[n])) s++; if ((a[mid]==z) && (mid!=0)) s++; } std::cout << s; } Твоя программа слишком долго работает | | Please help me! Where I did error??? Cpp | alievv313-14 | 1787. Turn for MEGA | 5 Feb 2015 20:01 | 1 | #include<iostream> using namespace std; int main() { int k, n, S =0; cin >> k >> n; if (k, n >= 1 && k, n <= 100) { int *A = (int*)malloc(n*sizeof(int)); for (int i = 0; i < n; i++) { cin >> A[i]; if (!(A[i] >= 0 && A[i] <= 100)) break; } for (int i = 0; i < n; i++) S += A[i] - k; cout << S << endl; } return 0; } Edited by author 05.02.2015 20:02 | | C# решение. Runtime error | ptb1994 | 1811. Dual-SIM Phone | 5 Feb 2015 11:48 | 2 | Вот мой код. показывает Runtime на 4 тесте. не могу разобраться из-за чего. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication4 { class Program { static void Main() { bool sol; string s = Console.ReadLine(); string[] sp = s.Split(' '); int n = int.Parse(sp[0]); int m = int.Parse(sp[1]); int q = n + 1; int q2 = n + 2; int p1, p2, p3; int[, ,] mas = new int[q2, q2, q2]; // основной массив для работы. for (int i = 0; i < m; ++i) // заполнение массива с клавиатуры. { string a = Console.ReadLine(); string[] b = a.Split(' '); int[,] c = new int[1, 3]; // интовый массив вводимой строки for (int j = 0; j < 3; ++j) { c[0, j] = int.Parse(b[j]); if (j == 2) // когда массив с заполняется, вынимаем индексы и цены. { p1 = c[0, 0]; p2 = c[0, 1]; p3 = c[0, 2]; mas[p2, p1, 0] = p3; // заполняем 0-ой слой основного массива ценами. } } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= n; ++j) { sol = true; for (int k = 1; k <= n; ++k) { if (mas[k, i, 0] == 0 & mas[k, j, 0] == 0) { mas[j, i, q] = 0; sol = false; } else { if (mas[k, i, 0] <= mas[k, j, 0] & mas[k, i, 0] != 0) { mas[j, i, k] = mas[k, i, 0]; } else { mas[j, i, k] = mas[k, j, 0]; } if (mas[j, i, q] < mas[j, i, k]) { if (sol) { mas[j, i, q] = mas[j, i, k]; } } } } if (mas[0, 0, 0] == 0) { mas[0, 0, 0] = mas[j, i, q]; } else { if (mas[j, i, q] > 0) { if (mas[0, 0, 0] >= mas[j, i, q]) { mas[0, 0, 0] = mas[j, i, q]; } } } } }
if (mas[0, 0, 0] < 1) { Console.WriteLine("No solution"); } else { Console.WriteLine(mas[0, 0, 0]); } Console.ReadKey(); } } } Я, конечно, не по теме, но зачем ты столько вложенности делаешь? В больших программах это же вообще ад. Например, else { if (mas[j, i, q] > 0) { if (mas[0, 0, 0] >= mas[j, i, q]) { mas[0, 0, 0] = mas[j, i, q]; } } } можно заменить на else if((mas[j, i, q] > 0)&&(mas[0, 0, 0] >= mas[j, i, q])) mas[0, 0, 0] = mas[j, i, q]; вообще одна-две строки. |
|
|