Общий форумThe answer is "N*(M+1)" yeah, it's mega simple problem... Yeah, it's simple but why my answer was wrong? anyone can help? Give me your code and I will help you Edited by author 31.01.2015 13:34 Edited by author 31.01.2015 13:34 why "N*(M+1)" i can't understand pls help "For each integer from 0 to M the function would calculate how many times this number appears in the N-element array..." Let's say N=2, so you have two-element array. Let's M=4, so you have to check whether there is any 0,1,2,3 or 4 (since from 0 to M) in each array... So total lines = 2*(4+1) Hope, it helped. how could 3 or 4 in the n? cause n = 2 so 3 or 4 are not in the array....for this reason why we don't use if else statement to see whether m is bigger than n or not...but we calculate it straightly?...can you please describe? because, a box is given as a clue ..... and you have to solve the problem according to that.. i guess :/ I got time limit in test#5 and I can't find out why if you are using G++ 7.1 try using visual studios 2017 compiler. Apparently one works faster than the other I get TLE on 22 test. What can you advise? 1)In solution you must find all primes <= 10^7. 2)You must use that n<=10^18. 1. find all primes up to 2 millions 2. if remainder > 2 millions, check if it is a prime Why do you take this number? big number N = X*Y*(p1*p2*p3*....*p18) = X*Y*(A) A = at least 2^18 = 262144 So, X*Y = at most 10^18 / 2^18 = 3 814 697 266 000 So either X or Y is less than 10^7 Edited by author 05.11.2019 20:56 Edited by author 05.11.2019 20:57 Each number maps to several letters of the alphabet. However, notice that several letters map to a single digit. If you can't go to the mountain, bring the mountain to you. Convert the words found in the dictionary for each case into digits, using the given map. Looking up which digit a letter maps to can be done in constant time if you use the right data structure. Then all that is left is to compare against the phone number given. Each number maps to several letters of the alphabet. However, notice that several letters map to a single digit. If you can't go to the mountain, bring the mountain to you. Convert the words found in the dictionary for each case into digits, using the given map. Looking up which digit a letter maps to can be done in constant time if you use the right data structure. Then all that is left is to compare against the phone number given. Can't believe!!!! Excellent idea!!!! If you can't go to the mountain, bring the mountain to you....wow what a statement! nice, but you must check such events: 1) word contains "ij" -> "11"(simple going letter by letter algorythm), that is not right it must transform into "1"( in dict "1":"ij"), but if word contains "ii" it must transform into "11". 2) if one word ends on some digit and another starts on it. we have words with "18" code and "89" code. Number "189". It depends, what letters words contain. There three alternatives: take both words, take with "18" or with "89". I got AC! It's nice problem! My algo works at O(3*N)=O(N). 1)BFS from any vertex and find the most remote vertex (let V); 2)BFS from V and find the most remote vertex (let U); 3)Create path from U and V; vertex(vertexes) in the middle is answer. Edited by author 04.08.2015 12:56 #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char name[20]; int N; scanf("%d", &N); int cost=200; int $=0; for(int i=0; i<N; i++) { scanf("%s", name); if(name[strlen(name)-4]=='+'&&name[strlen(name)-3]=='o'&&name[strlen(name)-2]=='n'&&name[strlen(name)-1]=='e') { cost=cost+200; } else { cost=cost+100; } } $=$+cost; if($==1300) { $=$+100; } printf("%d", $); return 0; } I got my code running due to the solutions posted.. But i want to understand the logic behind the division.. Any one? int main() { int n , m; cin >> n >> m; int *counter = new int [n]; for ( int i = 0 ; i < m ; i++ ) { int temp; cin >> temp; counter[temp-1]++; } for ( int i = 0 ; i < n ; i++ ) { float result = (float)counter[i] * (float)100 / (float)m; printf ("%.2f%%\n" , result); } delete[] counter; return 0; } (WA On Test 1) Where is "cout"? printf() also does the same work as cout<< I think the problem is from using int*counter.. Try using vector<int>counter(n); instead.. It worked fine when i tested it with the rest of your code Give me please 37 test. check your Knight with n = 3 Really nice tip, tvm bro. a,b=input('Введите числа через пробел: ').split(" ") a=int(a) b=int(b) print(a+b) test 1, wrong answer :( Got it. The text in Russian was not a good idea. just this: a,b=input().split() a=int(a) b=int(b) print(a+b) accepted! Hello Lisa . It and my error ) a = float(input(" ")) b = float(input(" ")) print(a+b) Runtime error Rus : Привет , у меня такая же ошибка . Выдает Runtime error #include <iostream> using namespace std; int prime[15001]; bool num[163848]; void sieve() { num[2]=true; prime[1]=2; long int i,j,k; for(i=3;i<163848;i+=2) num[i]=1; for(i=2,j=3;i<=15000;j+=2) { if(num[j]) { for(k=j;k*j<=163848;k+=2) num[k*j]=0; prime[i]=j; i++; } } } int main() { sieve(); int t; cin>>t; while(t--) { int m; cin>>m; cout<<prime[m]<<endl; } } Why am I getting RTE in test #1? Edited by author 13.09.2019 08:33 Edited by author 18.08.2019 21:37 What is the size of int in this oj? 2 or 4 Bytes? does anybody know anything about WA on that test? I got AC in 0.125s and 284KB!!! If you want my AC code,post me:happyzeyu@163.com Edited by author 25.12.2006 17:30 Edited by author 25.12.2006 17:30 I got AC in 0.109s abd 306KB!! Can I see your code? Post me:happyzeyu@163.com I got AC in 0.093 and 175KB :)) in russian that mean : "Пиписькомерство" *THUMBS UP* 0.031 - 189 Kb Just "Пиписькомерство"! :) Pascal - 0.093s 154 КБ PS "Пиписькомерство" - +1 =)) pascal 0.093s 122k d**kcomparing)))) My Java solution got TLE#20, but my dick is still bigger no matter what. haha, I am spend 0.078s and 197 k If you want my AC code, send mail to k421668239@gmail.com "ПИписькомерство")))+1 but for what it???for me more important the result!!!!! not how it is!!!!!! sorry for my english) If you have problems with test case 6, then please check the following: If you have wrong anwer at test 6, try this test: 4 3 3 4 5 Correct answer: 1 Because at ith minute, there is only a[i] cars come to the traffic jam. Good luck to you! Thanks to sign_in158. oh... i understand,thank you! I am very happy . Thank you . I am understand this Problem Thanks Edited by author 07.01.2015 01:03 Edited by author 21.02.2015 01:13 Edited by author 21.02.2015 01:14 Thank you. I understand now. n=2984210864 21975 21818 11974 11967 11964 11964 11964 11907 11707 n=120 22 53 23 22 22 22 22 22 22 22 n=1000000000 788888898 900000001 900000000 900000000 900000000 900000000 900000000 900000000 900000000 900000000 n=1595999 887689 1594800 998800 998800 998800 994800 897800 897800 897800 893800 n=2009999 1112889 2204000 1214000 1204000 1204000 1204000 1204000 1204000 1204000 1204000 n=123456789 96021948 130589849 100589849 96589849 96089849 96029849 96022849 96022049 96021959 96021949 n=10000 2893 4001 4000 4000 4000 4000 4000 4000 4000 4000 n=20000 6893 18000 8001 8000 8000 8000 8000 8000 8000 8000 n=30000 10893 22000 22000 12001 12000 12000 12000 12000 12000 12000 n=9999 10893 22000 22000 12001 12000 12000 12000 12000 12000 12000 Thanks for the tests! I got AC :) But... I have some small correntions: 1) N <= 1 000 000 000, so N = 2 984 210 864 is an impossible test 2) for N = 9999 the right output is: 2889 4000 4000 4000 4000 4000 4000 4000 4000 4000 Also this one is a good test: 11 1 4 1 1 1 1 1 1 1 1 correct first test is n = 29842 ans 10864 21975 21818 11974 11967 11964 11964 11964 11907 11707 and n = 9999 0 2889 1 4000 2 4000 3 4000 4 4000 5 4000 6 4000 7 4000 8 4000 9 4000 I deduced the formula, but in numbers with zeros it does not work(( #include <iostream> #include <math.h> #include <iomanip> #include <vector> #include <map> #include <string> #include <algorithm> using namespace std; int main() { int n; cin >> n; vector<int> vec; for (int i = 0; i < n; i++) { int num; cin >> num; vec.push_back(num); } int max = 0; int sum = 0, seredina = 0; int index = 0; multimap<int, int> index_sum; for (int i = 2; i < vec.size(); i++) { sum = 0; if (vec[i] >= vec[i - 1] && vec[i - 1] >= vec[i - 2]) { sum += vec[i] + vec[i-1] + vec[i-2]; index_sum.insert(pair<int, int>(i, sum)); } } for (auto it = index_sum.begin(); it != index_sum.end(); it++) { if (it->second > max) { max = it->second; sum = max; seredina = it->first; } } cout << sum << " " << seredina; return 0; } Edited by author 30.10.2019 21:02 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cmath> #include <algorithm> #include <set> #include <vector> #include <string> #include <cstdlib> using namespace std; void optimization() { cin.tie(nullptr); ios_base::sync_with_stdio(false); } int main() { optimization(); string s; int k = -1; cin >> s; char c[200000]; for (char & i : c) { i = ' '; } for (char i : s) { if (k > -1) { if (c[k] == i) { c[k] = ' '; k--; } else { k++; c[k] = i; continue; } } else { k++; c[k] = i; } } for (char i : c) { if (i != ' ') { cout << i; } } return 0; } You can use Disjoint-set data structure. Too complicated for such an easy problem Please, help. I can't help you without details of your algorithm. I have never encountered WA#5. I have some Stack-Overflow's because of critical mistake in my find_set function for Disjoint Set Union. After fixing AC. Edited by author 06.07.2017 09:50 You have to give us more information |
|