Общий форум| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения | | Python 3 . So strange . Runtime error (Russian plz) | Kozo Hoshino | 1000. A+B Problem | 31 мар 2021 18:15 | 4 | a = float(input("a:")) b = float(input("b:")) print(a+b) Edited by author 02.11.2019 14:57 Edited by author 02.11.2019 14:59 a = int(input()) b = int(input()) print(a+b) Runtime error . what ? You are trying to get 2 inputs but there is only one | | TL#23 | Zergatul | 2132. Разбиение графа. Версия 2 | 30 мар 2021 18:18 | 1 | TL#23 Zergatul 30 мар 2021 18:18 Check if your solution works correctly with dense graphs | | hint | Toshpulatov (MSU Tashkent) | 1781. Чистое программирование | 30 мар 2021 17:05 | 1 | hint Toshpulatov (MSU Tashkent) 30 мар 2021 17:05 suppose everything is good for the first 'i' columns, but the column is 'i' bad, then let's try to find such 'j' that, by doing the operation, our new column 'i' will become good, what properties should the column 'j' have ? If you can find 'j' just do operation swap (i, j) | | I keep getting Runtime Error Issue. Could someone help me resolve this? - PYTHON 3 based | Pratik Kumar Basu | 1030. Титаник | 30 мар 2021 16:35 | 1 | from sys import stdin, stdout, float_info import re from math import sin, cos, acos, fabs CONST_PI = acos(-1.0) CONST_EPSILON = 2.2204460492503130808472633361816 # CONST_PI = 3.141592653589793 data = [] def solve(a, b, c, d): a = a + (c / 3600) + (b / 60) # Checking the latitude and longitude position to determine positive pr negative degree if d == 'SL' or d == 'WL': a = -a a = a * CONST_PI / 180 return a def distComp(a): if fabs(a) < CONST_EPSILON: return 0 elif a > 0: return 1 else: return -1 # Input data = stdin.read().split() # # Test Input # data = ['Message', '#513.', 'Received', 'at', '22:30:11.', 'Current', "ship's", 'coordinates', 'are', '41^46\'00"', 'NL', # 'and', '50^14\'00"', 'WL.', 'An', 'iceberg', 'was', 'noticed', 'at', '41^14\'11"', 'NL', 'and', '51^09\'00"', 'WL.', '==='] # data = ['Message', '#513.', 'Received', 'at', '22:30:11.', 'Current', "ship's", 'coordinates', 'are', '36^46\'00"', 'EL', # 'and', '50^14\'00"', 'WL.', 'An', 'iceberg', 'was', 'noticed', 'at', '41^14\'11"', 'NL', 'and', '76^09\'00"', 'WL.', '==='] # Message Received # messageReceived = [int(s) for s in re.findall(r'\b\d+\b', data[4])] # hh = messageReceived[0] # mm = messageReceived[1] # ss = messageReceived[2] # print('\nMessage Received at: ', hh, mm, ss) # Ship's Latitude shipLatitude = [float(s) for s in re.findall(r'\b\d+\b', data[9])] x1 = shipLatitude[0] x2 = shipLatitude[1] x3 = shipLatitude[2] x4 = data[10] # print('\nShip Latitude: ', x1, x2, x3, x4) # Ship's Longitude shipLongitude = [float(s) for s in re.findall(r'\b\d+\b', data[12])] y1 = shipLongitude[0] y2 = shipLongitude[1] y3 = shipLongitude[2] y4 = data[13][:2] # print('\nShip Longitude: ', y1, y2, y3, y4) # Ice Berg's Latitude iceBergLatitude = [float(s) for s in re.findall(r'\b\d+\b', data[19])] a1 = iceBergLatitude[0] a2 = iceBergLatitude[1] a3 = iceBergLatitude[2] a4 = data[20] # print('\nIce Berg Latitude: ', a1, a2, a3, a4) # Ice Berg's Longitude iceBergLongitude = [float(s) for s in re.findall(r'\b\d+\b', data[22])] b1 = iceBergLongitude[0] b2 = iceBergLongitude[1] b3 = iceBergLongitude[2] b4 = data[23][:2] # print('\nIce Berg Longitude: ', b1, b2, b3, b4) shipLatitudeResult = solve(x1, x2, x3, x4) shipLongitudeResult = solve(y1, y2, y3, y4) iceBergLatitudeResult = solve(a1, a2, a3, a4) iceBergLongitudeResult = solve(b1, b2, b3, b4) dist = 6875.0/2 dist = acos(sin(shipLatitudeResult) * sin(iceBergLatitudeResult) + cos(shipLatitudeResult) * cos(iceBergLatitudeResult) * cos(shipLongitudeResult - iceBergLongitudeResult)) * dist print('\nThe distance to the iceberg:', round(dist, 2), 'miles.') if dist < 100: print('DANGER!') Edited by author 30.03.2021 16:37 | | Accepted simple way how to compute sum of distances | Gleb Dubosarskii | 1726. Кто ходит в гости… | 29 мар 2021 20:43 | 2 | After sorting of array of x and y all you need to do is to compute this two double sums sum(i=1)^n sum(j=1)^(i-1) (x_i-x_j) and sum(i=1)^n sum(j=1)^(i-1) (y_i-y_j). After simplifications one can obtain that they equal sum(i=1)^n x_i*(2*i-1-n) and sum(i=1)^n y_i*(2*i-1-n). After computations you divide final sum by C_n^2=n*(n-1)/2 and get required answer. Can you make your Formulations readable? | | What if I tell you that you don't need to find words placements | FatalityNT | 1164. Fillword | 25 мар 2021 01:13 | 1 | You can just count letters Edited by author 25.03.2021 01:13 | | Wrong answer 10 | Тимур | 2113. Пережить потоп | 24 мар 2021 12:28 | 1 | | | The time limit | Savchuk Nickolay | 1118. Нетривиальные числа | 23 мар 2021 17:29 | 1 | Good afternoon! I am a programmer-beginner. I have written the code for this task on c++, but the time limit is exceeded on the second test! The code is this: ( https://ideone.com/Rh98zQ) #include <iostream> using namespace std; float ghj(int a) {int m; m=0; for(int l=1; l<a; l++) {if(a%l==0) {m=m+l;}} float c=(float(int(m))); float b=c/a; return b;} int main() { int i,j; cin >> i >> j; float p=ghj(i); int n=i; for(int o=i; o<=j; o++) {if(ghj(o)<p) {p=ghj(o); n=o;}} cout << n; return 0; } Tell me, please, how can I optimize the code? | | 18 Wrong answer | Тимур | 2112. Полевые логи | 22 мар 2021 13:37 | 1 | | | Dynamic programming by profile? | sadovnik | 2143. Victoria! | 22 мар 2021 13:27 | 3 | Is it dynamic programming on the profile? How to apply it? Yes, it is. Let dp[i][mask] be the maximal number of passengers we can sit on the first i rows such that none of them sit close to each other and the i'th row is occupied exactly as in the mask (0 <= mask <= 63, if the j'th bit in the mask is 1, then the seat (j + 1) is occupied, otherwise it is not). Now, to compute dp[i][mask] we need to iterate through all possible masks "prev" of the (i - 1)'st row. For each such valid mask prev ("valid" means that none of the passengers on the (i - 1)'st and i'th rows sit close to each other) we have to relax our answer by dp[i][mask] = max(dp[i][mask], dp[i - 1][prev] + (the number ones in the mask)). Additionally, we can maintain the previous mask pointer[i][mask] = prev for each dp[i][mask] which gives us the best answer. When done with computing dp, we have to run through all valid masks of the last row and check whether dp[n][mask] >= k. If there is no such mask, then the answer is impossible. Otherwise, remember this mask and easily restore the answer by using those pointers to "prev" masks. Edited by author 01.05.2020 17:30 Edited by author 01.05.2020 17:30 Simple recursion with set<string,int> memorisation also works May be tests are weak | | WA#7 | pavelkaryukov | 1586. Трипростые числа | 22 мар 2021 02:32 | 2 | WA#7 pavelkaryukov 14 апр 2020 10:00 I had int32 overflow for the sum, switched to long and it worked | | wa#6... | visitor | 1322. Шпион | 19 мар 2021 03:55 | 3 | who can tell me what the test6 is? Thanks If you are using sort in your algo and sorting pairs<char ch,int position>, you must compare this pairs by a "ch", but if "ch"`s are equal - you must compare "position". Comparsion function may be like that: struct s{char c;int p;}; bool cmp(s a, s b) { if(a.c!=b.c) { return a.c<b.c; } return a.p<b.p; } Use stable_sort instead of sort (if you're doing on C/C++) | | WA on test 25 | Casio991ms | 1489. Точки на параллелепипеде | 18 мар 2021 22:31 | 1 | Getting WA on test 25, any test case? | | Нет теста на одно отрицательное число... | vtalgo21_gsavon | 1296. Гиперпереход | 17 мар 2021 02:24 | 2 | По условию, при входных n = 1 и единственном отрицательном значении ответ должен быть 0, но accepted получается и при неправильном решении такого теста... Либо я чего-то не понимаю... The test was added. Thank you. | | WA #26 | 👨🏻💻 Spatarel Dan Constantin | 2151. Маджонг | 16 мар 2021 16:14 | 1 | WA #26 👨🏻💻 Spatarel Dan Constantin 16 мар 2021 16:14 Input: 1a 1a 1a 1a 1a 1a 1a 1a 1a 1b 3b 5b 1c 1c Output: Tenpai | | help me pls! | Levan | 1083. Факториалы!!! | 13 мар 2021 01:32 | 7 | what is wrong? #include <iostream> #include <cmath> #include <map> #include <vector> using namespace std; int main() { int n; string str; cin >> n >> str;
int k = str.size(); int i = 0; int sum = 1; if(n % k == 0) { while(i != n / k) { sum *= n - k * i; i++; } } else { while(i != n / k + 1) { sum *= n - k * i; i++; } sum *= n % k; }
cout << sum << endl;
return 0; } Edited by author 31.12.2015 12:38 It would be great if you stop searching telepathists and show error message. Is it compilation error? Add "#include <string>" line. Is it WA? Strange. Code looks working. Is it any another error? Show it. Some people suppose n can be 20 so int is not enough for sum. Try to use long long sum. Test: 5 !!! answer 10, your answer 20 5!!! here k=3, 5 isn't divisible by 3 so you have to multiply 5%3=2 with 5*(5-3) so the answer is 5*2*2=20 | | why wrong on #T5 | Bu1bu1 | 1083. Факториалы!!! | 13 мар 2021 01:25 | 1 | #include<iostream> //#include<string> using namespace std; int main() { int n; string s; cin>>n; cin>>s; int sum=n; int len = s.size(); //cout<<len<<endl; int i =1; while((n-i*len)>1) { sum*=(n-i*len); i++; } if(n%len!=0) cout<<(sum*(n%len))<<endl; else cout<<sum*len<<endl; return 0; } | | hint | 👾_challenger128_[PermSU] | 1056. Центры сети | 13 мар 2021 00:05 | 1 | hint 👾_challenger128_[PermSU] 13 мар 2021 00:05 th: deleting leafes doesn't change centers | | BFS or DFS | svr | 1649. Абстракционизм в массы | 11 мар 2021 17:38 | 3 | BFS gave TLE 7. DFS must be much more successful. Reasons: 1) Easy to construct the son. 2) Easy and without memory reconstruct the father. DFS-TLE10 Therefore exists some strong mathematics in the problem to speed up algos. Edited by author 18.11.2008 09:24 Re: BFS or DFS Vedernikoff Sergey (HSE: EconomicsForever!) 18 ноя 2008 16:04 There exists very strong pruning idea, which makes brute-force extremely fast =) Yes, DFS is the way for this problem. My AC 0.015 solution can solve a 20x20 in about 700 recursions. Here's a hint for the problem: Pay close attention to the following sentence: "If the number of bacteria in a certain cell becomes 5, then 4 of them die because of overcrowding.". What would happen if this rule didn't exist? | | Examples for test 9 | Student_MAT-MEX | 1601. АнтиКАПС | 10 мар 2021 15:06 | 5 | Example 1: WHAT?????????????????????? Example 2: ?????????????????????? And... What is the answer? Example 1: WHAT?????????????????????? result: What?????????????????????? Example 2: ?????????????????????? result: ?????????????????????? These tests might cause runtime error if there're not all conditions observed in the code. Got AC just when passed these tests, thanks Try this: aaaaa...??? aaaa aaaaa.....!!! aa right answer: Aaaaa...??? Aaaa aaaaa.....!!! Aa "You are given Angela's message, which consists of uppercase English letters,..." -> Just uppercase letters in input. |
|
|