|
|
Common BoardWhat should i check if i have WA in test 5? Delete a rectangle if there is another one covering this one All the test cases I've come up with have been solved correctly by this method but no AC :( code: ``` #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> x(n, vector<int>(3, 0)); for (int i = 0; i < n; i++) { cin >> x[i][0]; cin >> x[i][1]; x[i][2] = i + 1; } sort(x.begin(), x.end()); auto med = (n - 1) / 2; cout << x[med][2] << " " << x[med + 1][2]; } ``` Edited by author 11.11.2024 16:23 Edited by author 11.11.2024 16:23 To answer my own question. The above code will select for the 2 median points. These don't necessarily create a median line. Consider the following test case: 4 0 10 1 1 2 2 3 10 The above alogorithm would select (1, 1) and (2,2), which partitions the plane into a section with 2 points, and a section with 0 points; the above approach is incorrect. Test 3 : input : 5 2 -1 -2 -3 -4 -5 output : 2 4 Test 4 : input : 2 0 1 -5 output : 0 0 Test 5 : input : 15 23 252 33 215 789 1000 123 -125 29 -45 -450 121 -555 -72 120 123 output : 23 113 Test 6 : 0 213 output Impossible Test 7 : input : 8 12 1 2 3 4 5 6 7 8 output : Impossible Test 10 : input : 0 0 output : 0 0 Test 15 : input : 2 12 1000 -1000 output : 12 2012 13 есть? Тест 4 точно не такой. По условию сказано, что x!=0. Я проверял, во всех тестах x!=0. Тест 10 тоже не такой. Edited by author 28.01.2014 07:04 Edited by author 28.01.2014 07:05 правильно подметил Vitaliy. Еще возможен такой вариант : input : 3 2 0 -2 4 output : Impossible Невозможен, "Все координаты, включая x, не равны нулю" You have an error in tests 4 and 10: "Each coordinate, including x, is non-zero and doesn't exceed 1000 in absolute value." 15 isn't it. I have WA15, but on this test my program outputs right answer Send me the answer or I'll kick you! Почему задачу 1785 нельзя отправить на проверку и почитать её условие, однако она идёт в зачет количества решенных задач? Чтобы новые пользователи никогда не могли решить все задачи? Так что ли? Thanks for raising the issue. The problem is restored. Hi, I've got a compilation error in Rust (id: 10760679) because of a feature that appears in edition 2021, and the compiler on Timus uses some previous edition. Any plans to compile Rust code in edition 2021? It's already 2024 and the edition is stable (in fact, a newer edition will be released in several months), so it makes no sense to stick to an older edition. The current version of Rust compiler is 1.75.0, which was released on 28 December, 2023. Thanks for explanation. The command line changed to: rustc -O --edition 2021 %1 Starting from my second attempt (first was WA) I am always getting "Checker failed" independently of the code. Even, if I submit the first attempt's code, which was WA. I see that my submissions were tested. But there is still a problem: I suspect, that checker is not correct, as it rejected another optimal answer. Compare submissions 10791903 and 10791934 : they have only difference in "<" / "<=" in "if (d[..] < answer) { ..update answer..}". One of them is AC, another one is WA40. Sqrtl is inaccurate, check the numbers next to it Your algo is based sweep line or other ? I think, you should delete old segment before add new. I had wa14 until i do this and get AC) вообще, в чем смысл писать на английском, если подовляющее большинство посетителе сайта знают русский? кароч, я не смог придумать тест который у меня бы все ломал, но когда поправил эту багу, все стало хорошо) Edited by author 10.08.2025 21:25 How can I improve memory usage in this code? #include "bits/stdc++.h" using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); short n; cin >> n; vector<pair<int,short>> s(n, pair<int,int>()); for (int i = 0; i < n; i ++) { cin >> s[i].first; s[i].second = i; } sort(begin(s),end(s)); for (short i = 1; i < n; i ++) { if (s[i].first == s[i - 1].first) { s.erase(begin(s) + i); n --; i --; } } vector<vector<short>> dp(n + 1, vector<short>(n + 1, 0)); for (short i = 1; i < n - 1; i ++) { short l = i - 1; short r = i + 1; while (0 <= l && r < n) { int dfl = s[i].first - s[l].first; int dfr = s[r].first - s[i].first; if (dfl == dfr) { dp[i][r] = dp[l][i] + 1; l --; r ++; } else if (dfl > dfr) { r ++; } else { l --; } } } if (1 == n) { cout << "1\n1\n"; } else { short mx = -1; short di = 0; short dj = 0; for (int i = 0; i < n - 1; i ++) { for (int j = i + 1; j < n; j ++) { if (dp[i][j] >= mx) { mx = dp[i][j]; di = i; dj = j; } } } int df = s[dj].first - s[di].first; mx += 2; cout << mx << '\n'; for (; -1 < di;) { cout << s[dj].second + 1 << ' '; dj = di; di = -1; for (short i = 0; i < dj; i ++) { if (s[dj].first - s[i].first == df) { di = i; break; } } } cout << s[dj].second + 1 << '\n'; } } Don't use std::vector at all. Especially for 2D arrays. Vector can be twice more than you suppose ) Could you please give any hints or tests? #include <iostream> using namespace std; int main() { int n; cin >> n; long a = 1; long b = 1; long ans = 0; if(n == 1 || n == 2){ ans = 1; } else { while (n - 2 > 0){ ans = a + b; a = b; b = ans; n--; } }
cout << 2 * ans; return 0; } If you have "Time limit exceeded", just use sys.stdin.read()... and it will put load on memory, as I suppose reading huge amount of data via input() takes forever. Стал изучать программирование только для того, чтобы кекать с таких заданий N = int(input()) p = [] maxi = 0 for i in range(N): p.append(int(input())) summi = sum(p) for i in range(N): fsummi = sum(p[i:len(p)-i-1]) if fsummi > maxi and fsummi>summi : maxi = fsummi maxi2 = 0 for i in range(0, N-1): nsummi = sum(p[i::]) jsummi=summi-nsummi if nsummi > jsummi: maxi2 = nsummi else: maxi2 = jsummi if maxi>maxi2: print(maxi) elif summi> maxi and summi>maxi2: print(summi) else: print(maxi2) |
|
|