Common Board| Show all threads Hide all threads Show all messages Hide all messages | | O(n) Solution | Aditya Singh | 1247. Check a Sequence | 11 Dec 2017 08:13 | 1 | Subtract 1 from each element Apply window to the array for max sum of S #include <bits/stdc++.h> using namespace std; #define repl(i,x,n) for(long long i=(long long)(x);i<(long long)(n);i++) #define rep(i,x,n) for(long i=long(x);i<long(n);i++) int main() { //ifstream cin("input.in"); //ofstream cout("output.out"); ios::sync_with_stdio(0);cin.tie(0); long n,s,a[100009],p=0; cin>>n>>s; bool flag=1; rep(i,0,n) { cin>>a[i]; a[i]--; } rep(i,0,n) { p+=a[i]; if(p>s) flag=0; p=max(p,0l); } if(flag) cout<<"YES"; else cout<<"NO"; } Edited by author 11.12.2017 08:23 | | WA #12 I think it's all fine, but... Please, help | _Link | 1024. Permutations | 10 Dec 2017 15:06 | 2 | This works correct even with 1000 numbers. (What else compilator wants? )) #include <stdio.h> int nod(int a, int b){ while (a != 0 && b != 0){ if (a > b) a = a % b; else b = b % a; } return a+b; } int main(){ int size; int result = 1; scanf_s("%i", &size); int arr[1001]; bool mask[1001]; for (int i = 0; i < size; ++i) scanf_s("%i", &arr[i]); for (int i = 0; i < size; ++i){ int k = 1, temp = arr[i]; while (temp != i + 1){ temp = arr[temp - 1]; ++k; } if (mask[k] != false){ mask[k] = false; result =result/nod(result,k) * k; } } printf("%i", result); } I tried to repair your code [code deleted] Edited by moderator 04.12.2019 20:38 | | Tests or help please | Ghiorghiu Ioan-Viorel | 1024. Permutations | 10 Dec 2017 14:53 | 2 | If you don't feel like reviewing my code at least give me some tests please. So... um... I think my code should work... I tested it along with an accepted program... and it worked fine... Here's the code: #define DM 1001 #include <bitset> #include <iostream> #include <set> using namespace std; bitset <DM> bs; bool verif; int n, c, lg[DM], mp[DM]; long long v; set <int> s; void recursiv (int a) { bs[a] = 1; ++v; if (s.find(mp[a]) != s.end()) return; s.insert(a); recursiv(mp[a]); } int main () { cin >> n; for (int i = 1; i <= n; ++i) { cin >> mp[i]; if (mp[i] == i) bs[i] = 1; } for (int i = 1; i <= n; ++i) if (!bs[i]) { recursiv(i); s.clear(); lg[++c] = v; v = 0; } for (v = lg[1]; !verif; ++v) { verif = 1; for (int i = 1; i <= c; ++i) if (v%lg[i] != 0) verif = 0, i = c + 1; } cout << v - 1; return 0; } Your solution is good, but try to fix these problems : Test 3 1 2 3 and don't use set. You will get time limit for n = 1000 sorry for my poor english! | | WA#12 | Kirishima Touka | 1049. Brave Balloonists | 10 Dec 2017 09:03 | 1 | WA#12 Kirishima Touka 10 Dec 2017 09:03 I really don't understand why i got WA #12...i try a lot of tests and i always have the right answer, could anyone give me test 12, please. | | WA#7 please help! | micrus | 1002. Phone Numbers | 9 Dec 2017 21:49 | 1 | example = {'i': 1, 'j': 1, 'a': 2, 'b': 2, 'c': 2, 'd': 3, 'e': 3, 'f': 3, 'g': 4, 'h': 4, 'k': 5, 'l': 5, 'm': 6, 'n': 6, 'p': 7, 'r': 7, 's': 7, 't': 8, 'u': 8, 'v': 8, 'w': 9, 'x': 9, 'y': 9, 'o': 0, 'q': 0, 'z': 0} def create_words(number, amount): words = {} for i in range(int(amount)): word = str(input()) key = "" key = "".join([str(example.get(j)) for j in word]) if key in str(number): words[key] = word return words def create_answers(number, words): answers = {} for i in words.keys(): if i != number[:len(i)]: continue answer = [words[i]] answer_key = i copy = number[len("".join(answer)):] x = len(copy) while x > 0: if copy[:x] in words.keys(): answer.append(words[copy[:x]]) answer_key += copy[:x] copy = copy[x:] x = len(copy) + 1 x -= 1 if len(answer) == 0: continue elif len(answer) in answers.keys(): continue elif answer_key == n: answers[len(answer)] = answer else: continue return answers while True: n = input() if int(n) == -1: break a = input() i = create_answers(n, create_words(n, a)) if len(i) == 0: print("No solution.") else: y = min(i.keys()) print(" ".join(i[y])) Edited by author 09.12.2017 22:06 | | Why WA4? | JamesBond_007 | 1109. Conference | 8 Dec 2017 16:23 | 4 | Why WA4? JamesBond_007 25 Oct 2016 14:22 #include <iostream> #include <vector> #include <set> using namespace std; set < pair <int, int> > S; set < pair <int, int> > :: iterator it; vector <int> A[1111], B[1111]; int n, k, m, x[1111], y[1111], res, X[1111], Y[1111]; bool used[111111]; void cut_x(int v){ for (int i = 0; i < k; i ++){ if(!used[i] && X[i] == v && y[Y[i]] > 1){used[i] = true; y[Y[i]] --; res --;} } } void cut_y(int v){ for (int i = 0; i < k; i ++){ if(!used[i] && Y[i] == v && x[X[i]] > 1){used[i] = true; x[X[i]] --; res --;} } } int main(){ cin >> n >> m >> k; res = k; for (int i = 0; i < k; i ++){ int u, v; cin >> X[i] >> Y[i]; A[X[i]].push_back(Y[i]); B[Y[i]].push_back(X[i]); x[X[i]] ++; y[Y[i]] ++; } for (int i = 1; i <= n; i ++) S.insert(make_pair(x[i], i)); for (it = S.begin(); it != S.end(); it ++){ pair <int, int> v = *it; if(v.first == 1){ cut_y(A[v.second][0]); }else{ cut_x(v.second); } } cout << res; } Your idea has bug you have to think again clearly! | | how to submit in visual C++ 2017 | Shen Yang | 1589. Sokoban | 8 Dec 2017 11:43 | 1 | visual C++ 2017 can't use gets() too egg hurt | | Python 3. Code Improvement. | Dhruv Somani | 1203. Scientific Conference | 8 Dec 2017 11:11 | 3 | I wrote the following code. It takes 0.748 s, 13 524 KB. Can you suggest something faster? [code deleted] Edited by author 01.05.2016 22:19 Edited by moderator 04.12.2019 21:38 Why does this solution work? Can anybody prove that? I dont understand why it work. Thanks! you can replace for x in range(confs): l.append(tuple(map(int, input().split()))) by for x in sys.stdin: l.append(tuple(map(int, x.strip().split()))) | | How did you find the alhorithm, AC-guys? | Komarov Dmitry [Pskov SPI] | 1639. Chocolate 2 | 8 Dec 2017 00:33 | 9 | I hate such tasks so much! It's not programming, it's pure math!! So how did you proved the algorithm? I broke my brain truying to solve it!! You must understand that there are needed as mush cuts as there are little squares in the bar (minus 1). Imagine that the bar has the shape 1xnm. How many cuts? (n-1), yeah? Since at the very end all pieces are the little squares, the shape of intermediate cuts doesn't matter, the total cuts count to (n-1). to melkiy Komarov Dmitry [Pskov SPI] 12 Nov 2009 11:17 Thank you very much!) You saved hours of my life! My observation: one cut buys us plus one piece of chocolate, because we can cut only one piece at a time. So, after the first cut we have two pieces, after the second one, we have three pieces, and so on until we have n*m pieces. Now it's easy to see that we only need to check the parity of n*m That's the thought. It is conjectured that however youcut it during the process, the total steps are always the same, but I didn't prove it. Now Iget it. Thank you. There is a winning strategy for the second player is to mirror moves of the first, but if N or M is even, the first player can split it in two halves - the only move cannot be mirrored and wins. my solution: #include <iostream> #include <string> #include <vector> #include <set> #include <queue> #include <map> #include <stack> #include <algorithm> #include <bitset> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #define F first #define S second #define ll long long #define len length() #define sqr(x) x*x #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define bp(x) __builtin_popcount(x) #define INF numeric_limits<long long int>::max() #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std;
int n,m; main(){ scanf("%d%d",&n,&m); if(n*m%2==0) puts("[:=[first]"); else puts("[second]=:]");
return 0; } mathem much important in programming. U MUST know that, if u dont wants to write indian code | | runtime error #4 | MassterMax | 1100. Final Standings | 7 Dec 2017 12:02 | 2 | Help me please, if you can I wrote a program, but i got rt#4 i don't know why I tried different tests(M=0;M=100 and other) but it was all in vain Very grateful for any help! Sorry for bad English Edited by author 03.12.2017 20:04 | | admin,please check test case 18 | Shen Yang | 1589. Sokoban | 7 Dec 2017 12:01 | 2 | I think this is a no solution test I output empty and pass this test... wa haha AC again,hahahaha two hardest problems | | Um... Okay | Fast Bastards | 1100. Final Standings | 7 Dec 2017 12:00 | 1 | #include <bits/stdc++.h> #define pb push_back using namespace std; int main() { int n; cin >> n; vector<pair<int, int> > v; int x, p; for(int i = 1; i <= n; i ++) { cin >> x >> p; v.pb({p, x}); } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); for(int i = 0; i < n; i ++) { cout << v[i].second << " " << v[i].first << "\n"; } } But it is same sort | | My code crashed at 10th test | Rabbit Girl ♥ | 1067. Disk Tree | 6 Dec 2017 20:58 | 1 | I implemented a prefix tree using pointers and it crashed. I don't know why : for me it worked at max test. But as soon as I moved to an array implementation, it worked! | | wa22 | AGrigorii [Yaroslavl SU] 🔥 | 1937. Davy Jones’s Organ | 6 Dec 2017 11:05 | 2 | wa22 AGrigorii [Yaroslavl SU] 🔥 5 Jul 2017 18:03 AC by anti-"antihash-test" hash approach. Edited by author 06.12.2017 11:06 | | How I solved it. | Mahilewets | 1792. Hamming Code | 5 Dec 2017 20:25 | 2 | I have used bitmasks. There are only 16 possible Hamming codes. So, I have precalculated. Then check, whether input is a valid code. Then try to find such valid code that it differs from input in exactly one position (I have used xoring for that) and print that codr. Don't forget about zero code. That is a special case. Можно ведь и проще гораздо) Составить три булевых функции (они вполне конкретно прописаны в условии), принимать за ошибку по очереди каждую цифру и смотреть, какие из функций при этом должны вернуть истину, а какие ложь. Остаётся прописать 8 if, один из них будет на код без ошибок, остальные - на соответствующую ошибку. Остаётся её исправить и вывести ответ) | | WA6: use this stupid code for correct input | dgorlov | 1316. Electronic Auction | 4 Dec 2017 16:00 | 4 | i have WA6 for correct input of price use procedure like this int read_price(void) { double f; fscanf(inf,"%lf",&f); return (int)((f+1e-9)*100.0); } and you got AC Thank you very much!I got AC Can you explain me please when expressions (int) (f * 100) and (int)((f+1e-9)*100.0)can differ. (I got AC after using this method, but still can't figure out what the problem is). Thanks in advance :) Edited by author 07.10.2013 03:17 I don't understand ! Why when I read data like integer before and after point : int price = before * 100 + after -> is wa6 and when I read data like double: double d; scanf("%lf, &d); int price = (int)(d * 100.0 + 0.1) -> is ok | | How to use DP in this problem? | Karolis Kusas | 1427. SMS | 3 Dec 2017 20:44 | 4 | Hello. Could somebody tell me a right DP approach to this problem. I couldn't figure out the solution better than O(|S|*M). |S| - length of the string. Easy problem. Let dp[i] - answer for string S1..Si. Then dp[i]=min(dp[i],dp[i-n]+1). (Maximum possible N-characters message). If last_idx - index of last "bad" character, then dp[i]=min(dp[i],dp[max(last,i-m)]+1). If current character is "bad" - update last_idx. It's O(|S|) solution. A pure greedy problem. You don't need to use any array, the algorithm is very simple: For each characters, just check if you can add it to the current message, if not you will create a new message and then add it to this message. What is the BAD character in string??? | | 600 lines of code to get wa21 :( | Martin_fmi | 1199. Mouse | 3 Dec 2017 20:28 | 4 | Hi everybody, After a lot of testing I have wa21 ... Is there anything spacial about this test case ? Thanks in advance. Edited by author 18.07.2009 22:28 Yes, be sure you will not output more than 1000 vertices. | | C hint WA №1 | Ceban | 1068. Sum | 3 Dec 2017 19:52 | 1 | int n,i=0; -- AC int n,i; -- - WA №1 | | What is wrong? WA#4 | jack | 2031. Overturned Numbers | 2 Dec 2017 15:40 | 2 | import java.util.Scanner; public class ex2031 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if(n==1){ System.out.println("11"); }else{ if(n==2){ System.out.println("11"+" "+"01"); }else{ if(n==3){ System.out.println("001"+" "+"66"+" "+"86"); }else{ if(n==4){ System.out.println("16"+" "+"06"+" "+"68"+" "+"88"); }else{ System.out.println("Glupenky Pierre"); } } } } } } Он не может использовать трёхзначные числа |
|
|