| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| One test to rule them all | Afigan | 1003. Чётность | 13 май 2019 13:56 | 2 |
100000000 10 1 5 even 6 10 even 11 18 even 19 25 even 1 8 even 16 25 even 16 40 even 9 40 odd 1000 5000 odd 1000 6000 odd -1 answer: 7 why is it 7? could you explain? |
| Fixed runtime errorr 25 | Arseniy | 1604. В Стране Дураков | 13 май 2019 04:24 | 1 |
I had runtime error 25, but when i surrounded sorting with try catch it accepted Any ideas why? |
| Python why answer is wrong? | Artem | | 13 май 2019 00:12 | 1 |
#solution 1068 x=int(input("enter your number: ")) def factorial(x): if x>0: return x + factorial(x - 1) elif x<0: return x + factorial(x+1) if x==0: return 0 y=factorial(x) if x<0: print(y+1) else: print(y) |
| Python 3 solution without loops | ZEMlan | 1068. Сумма | 13 май 2019 00:07 | 2 |
n = int(input()) if n > 0: print(int(n*(n+1)/2)) elif n == 0: print('1') else: print(int(n*(n-1)/-2 + 1)) |
| delete | Viktor Krivoshchekov`~ | 1102. Странный диалог | 10 май 2019 23:08 | 1 |
delete Viktor Krivoshchekov`~ 10 май 2019 23:08 delete Edited by author 04.10.2020 16:38 |
| What is test #38? | Mikhail Krivenko | 1510. Порядок | 8 май 2019 17:21 | 2 |
What's wrong with test #38? I got AC with sorting but failed on majority search? I've got AC without sorting. I have failed on #38 recently on a test like: 7 4 1 1 2 1 1 3 |
| TEST 2 : | Adhambek | 1506. Столбцы чисел | 8 май 2019 13:23 | 3 |
input : 15 4 1 2 30 994 50 600 700 999 900 990 991 992 993 40 800 output : 1 50 900 993 2 600 990 40 30 700 991 800 994 999 992 input:: 9 2 1 2 3 4 5 6 7 8 9 output:: 1 6 2 7 3 8 4 9 5 9 4 100 10 1 0 999 2 999 999 1 out: 100 0 999 10 999 999 1 2 1 Edited by author 08.05.2019 13:24 Edited by author 08.05.2019 13:24 |
| WA4 | Badr | 2091. Естественный отбор | 7 май 2019 20:38 | 1 |
WA4 Badr 7 май 2019 20:38 If you have WA4, try a 100x100 matrix with all 1 or with all 0. Edited by author 12.05.2019 20:53 |
| No subject | myb | 1297. Палиндромы | 7 май 2019 15:12 | 1 |
|
| No subject | Bart11 | 1000. A+B Problem | 7 май 2019 14:29 | 2 |
import java.util.Scanner; public class task9 {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); int cl = 0; int stroka =1; int[][] mas = new int[n][m]; for(int i=0;i<n;i++){ if(stroka%2==1){ for(int j=0;j<m;j++){ mas[i][j]=cl; cl++;
} stroka++; } else{ for(int j=m-1;j>=0;j--){ mas[i][j]=cl; cl++; } stroka++; } } System.out.println(mas[x-1][y-1]);
}
} ¼script¾alert(¢1¢)¼/script¾ Edited by author 07.05.2019 14:29 Edited by author 07.05.2019 14:36 |
| OFFER YOU SOME CLARIFICATION | scidylanpno | 1628. Белые полосы | 7 май 2019 12:14 | 1 |
The problem is to find how many l*1 or 1*l while rectangles that do not *included* by each others. |
| Are there another solution? | scidylanpno | 2014. Женя переезжает от родителей | 7 май 2019 11:06 | 1 |
My solution is O(NlogN),but I thought there may be some solutions use only O(N) time, thank you for your sharing! |
| sort AC | xyqxyq | 1100. Таблица результатов | 7 май 2019 08:05 | 1 |
Question requirements are ordered without changing order #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 150005; struct Node { int index; int ID; int mount; }node[maxn]; int N; bool cmp(Node &a, Node &b) { if (a.mount != b.mount) { return a.mount > b.mount; } else { return a.index < b.index; } } int main() { scanf("%d", &N); for (int i=0; i<N; i++) { scanf("%d%d", &node[i].ID, &node[i].mount); node[i].index = i; }
sort(node, node + N, cmp);
for (int i=0; i<N; i++) { printf("%d %d\n", node[i].ID, node[i].mount); } return 0; } |
| both the compiler and the header file matter a lot | scidylanpno | 1220. Stacks | 6 май 2019 14:09 | 1 |
I tried so many time until I change `#include<bits/stdc++.h>` to `#include<stdio.h>`. And then I did a small experience: for the same code, Visual C++ 2017 -- 612 KB Visual C 2017 -- 620 KB GCC 7.1 / Clang++ 4.0.1 -- 652 KB G++ 7.1 -- 700 KB Hope it helps~ |
| WA#3; what's wrong with my code, I am losing all my mind. :'( | Neeraj Kumar | 2023. Дональд-почтальон | 6 май 2019 02:26 | 3 |
#include <iostream> int main(void){ char nameOfKid[8]; int noOfLetters; std::cin >> noOfLetters; std::cin.ignore( 256, '\n') ; int cur, temp, steps, newcur; newcur = 0; cur = 0; steps= 0 ; for (int i = 0 ; i < noOfLetters; ++i){
std::cin.getline(nameOfKid, 8);
temp = static_cast<int>(nameOfKid[0]); switch(temp){ case 65: case 80: case 79: case 82: newcur = 1; break; case 66: case 77: case 83: newcur = 2; break; case 68: case 71: case 74: case 75: case 84: newcur = 3; break;
} if ((newcur!=cur) && (i!=0)){ steps = steps + ((newcur>cur) ? (newcur-cur): (cur-newcur));
} cur = newcur; } std::cout << steps; return 0; } You can store first letters with their's corresponding place like that: int m[256]; m['A'] = m['P'] = m['O'] = m['R'] = 1; m['B'] = m['M'] = m['S'] = 2; m['D'] = m['G'] = m['J'] = m['K'] = m['T'] = m['W'] = 3; #include<bits/stdc++.h> using namespace std; int main(){ map<char,int>mp; mp['A'] = 1; mp['O'] = 1; mp['R'] = 1; mp['P'] = 1; mp['B'] = 2; mp['M'] = 2; mp['S'] = 2; mp['D'] = 3; mp['G'] = 3; mp['J'] = 3; mp['K'] = 3; mp['T'] = 3; mp['W'] = 3; int n,ans=0,pre=-1; string s; cin>>n; while(n--){ cin>>s; if(pre== -1){ pre = mp[s[0]]; }else{ ans += abs(mp[s[0]] - pre); pre = mp[s[0]]; } } cout<<ans<<endl; return 0; } i also got WA#3 doing in same way. |
| HINT. To all whose solution using merge sort gets WA on test #5. | Vladislav Nikolaev | 1090. Теперь ты в армии | 4 май 2019 18:57 | 1 |
Solving the problem using the merge sort approach (counting inversions while merging subsequences - plus one inversion in a case of element from the left subseq greater than the element from the right) looks feasible (and maybe evident) to implement. But there is one caveat: it is crucial to count not only the one inversion in a case *cur_left > *cur_right, but count elements in a range [cur_left + 1, right_begin) as "inverted" too. That follows from the fact that merged subarrays are sorted in ascending order, so if we encountered the (*cur_left > *cur_right) case, then elements in a range [cur_left + 1, right_begin) satisfies that too and could be counted as inversions. Hope I stated that clearly. Edited by author 04.05.2019 18:59 Edited by author 06.05.2019 06:44 |
| Important thing about ignoring calls | Rahovski | 1576. Телефонные тарифы | 4 май 2019 14:58 | 1 |
You need to remember that string "no more than 6 sec". It means that you need ignoring all calls with 0 min and 0-6 sec including 6 sec. It's important for tests. |
| Got a WA on #27 | Kenith Chu | 1297. Палиндромы | 3 май 2019 11:57 | 3 |
my cpp code is following: #include <cstdio> #include <algorithm> #include <cstring> #define fi first #define se second using namespace std; typedef long long LL; typedef pair<int, int> P; const int N = 5010, INF = 0x3f3f3f3f; int c[N], sa[N], x[N], y[N]; void GetSA(int *r, int *sa, int n, int m) { for (int i = 1; i <= m; i++) c[i] = 0; for (int i = 1; i <= n; i++) c[x[i] = r[i]]++; for (int i = 2; i <= m; i++) c[i] += c[i - 1]; for (int i = n; i >= 1; i--) if (c[x[i]]) sa[c[x[i]]--] = i; for (int k = 1, p = 0; k <= n; k <<= 1, p = 0) { for (int i = n - k + 1; i <= n; i++) y[++p] = i; for (int i = 1; i <= n; i++) if (sa[i] > k) y[++p] = sa[i] - k; for (int i = 1; i <= m; i++) c[i] = 0; for (int i = 1; i <= n; i++) c[x[i]]++; for (int i = 2; i <= m; i++) c[i] += c[i - 1]; for (int i = n; i >= 1; i--) sa[c[x[y[i]]]--] = y[i], y[i] = 0; swap(x, y); x[sa[1]] = p = 1; for (int i = 2; i <= n; i++) x[sa[i]] = (y[sa[i]] == y[sa[i - 1]] && y[sa[i] + k] == y[sa[i - 1] + k]) ? p : ++p; if (p == n) break; m = p; } } int hei[N], rnk[N]; void GetH(int *r, int *sa, int n) { for (int i = 1; i <= n; i++) rnk[sa[i]] = i; for (int i = 1, k = 0, j; i <= n; hei[rnk[i++]] = k) for (k ? k-- : 0, j = sa[rnk[i] - 1]; r[i + k] == r[j + k]; k++); } int n; int s[N]; char str[N]; bool check(int a, int b, int len) { return n - a + 2 == b + len; } int main() { int mx = 0; scanf("%s", str + 1); int len = strlen(str + 1); for (int i = 1; i <= len; i++) s[i] = str[i], mx = max(mx, s[i]); s[len + 1] = '$'; for (int i = len; i >= 1; i--) s[len * 2 - i + 2] = str[i]; n = (len << 1) + 1; GetSA(s, sa, n, 1000); GetH(s, sa, n); P ans = P(1, -1); for (int i = 3; i <= n; i++) { int a = max(sa[i - 1], sa[i]), b = min(sa[i - 1], sa[i]); if (!(a > len + 1 && b <= len)) continue; if (check(a, b, hei[i]) && P(hei[i], -b) > ans) ans = P(hei[i], -b); } int pos = -ans.se; for (int i = pos; i < pos + ans.fi; i++) printf("%c", str[i]); puts(""); return 0; } I've tried to enlarge the alphabet size, but there's no effect. I also test lots of random test cases, all of them are correct. I hope someone could give me a hack data. Edited by author 21.02.2019 15:57 All right, I knew what's wrong... can you tell me why you wrong? i wrong on #27 too |
| Hints & ideas | decay | 1972. Тестирование игры | 1 май 2019 18:36 | 1 |
A problem asks to find longest path in Hyper cube graph that visits each vertex at most once. If two numbers have odd amount of bits in common then there is always a Hamiltonian path (length 2^n). Parity of common bits is checked using xor. If parity is even then one can build a path of length 2^n - 1. This path can be built by successively building Hamiltonian paths on lower dimension cube. That is, build a path of length 2^(n - 1) and recurse to find path of length 2^(n - 1) - 1. So, the solution is built around knowing how to construct Hamiltonian path. There is, in fact, a very simple approach. My algorithm works in O(2^n) and doesn't use extra memory. |
| Hint! | some_programming_novice | 1828. Приближение прогрессией | 29 апр 2019 17:27 | 1 |
Hint! some_programming_novice 29 апр 2019 17:27 Let those two partial derivatives equal to zero. |