Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | TLE on #8 | Shervin | 1423. Басня о строке | 11 фев 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. Уральские бифштексы | 11 фев 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. НОД 2010 | 10 фев 2015 20:23 | 2 | TLE Petru Trimbitas💯 3 дек 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. Трипростые числа | 9 фев 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. Медиана последовательности | 9 фев 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. Число Исенбаева | 9 фев 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. Число Исенбаева | 9 фев 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. Квадратный корень | 8 фев 2015 09:54 | 2 | WA#2 LNCP 8 фев 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. Чётность | 8 фев 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!!!!!! | Vasily Slesarev | 1286. Космолёт марки ВАЗ | 7 фев 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-ичные числа. Версия 3 | 7 фев 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. Такси | 7 фев 2015 17:20 | 4 | wa 5 ziwert 21 сен 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 Bakhodir Boydedaev 29 ноя 2014 17:21 | | You are required to be just very attentive to solve this problem | Evgeniy[VVV] | 1804. Пулемётчицы в плей-офф | 7 фев 2015 17:16 | 1 | | | Помогите time limit wa8 | NikolosAvr | 1196. Экзамен по истории | 6 фев 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. Поворот на МЕГУ | 5 фев 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 телефон | 5 фев 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]; вообще одна-две строки. | | WA 18 | crc | 1085. Встреча | 4 фев 2015 18:42 | 2 | WA 18 crc 4 фев 2015 14:29 Ok I forgot about this: (if there are several numbers choose the minimal one) | | Ошибка в тестах. | Evgeniy | 1083. Факториалы!!! | 4 фев 2015 16:43 | 1 | Если изменить правило 2(если n делится на k) и вместо k умножить на 1, то все заработает. Определение 1. n!!…! = n(n−k)(n−2k)…(n mod k), если n не делится на k; n!!…! = n(n−k)(n−2k)…1, если n делится на k (знаков ! в обоих случаях k штук). | | Очень легкая задача. | Evgeniy[VVV] | 1680. Первое невыходящее | 3 фев 2015 17:27 | 1 | | | a question | alireza est | 1001. Обратный корень | 3 фев 2015 15:39 | 1 | who knows what the meaning of set of numbers is??? is it true that the user must specify how many numbers must be taken? Edited by author 03.02.2015 23:09 |
|
|