| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| С# Solution | Lada Belonogova | 1567. SMS-спам | 18 янв 2019 13:22 | 1 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace phrase { class Program { static int First(string input, string[]array) { int col = Convert.ToInt32(input.Length); if (col>0&&col<=1000) { int countArr = 0,countStr = 0,c = Convert.ToInt32(array.Length),count = 0,indexStr=0; for (; countArr < c; countArr++) { for (; (indexStr = input.IndexOf(array[countArr], countStr)) !=-1; countStr = indexStr + 1) { count++; } countStr = 0; } return count; } return 0; } static void Main(string[] args) { string[] one = new string[] { "a", "d", "g", "j", "m", "p", "s", "v", "y", ".", " " }; string[] two= new string[] { "b", "e", "h", "k", "n", "q", "t", "w", "z", "," }; string[] three = new string[] { "c", "f", "i", "l", "o", "r", "u", "x", "!" }; string input = Console.ReadLine(); int a = First(input,one); int b = First(input,two); int c = First(input,three); Console.WriteLine(a+(b*2)+(c*3)); } } } |
| I have AC with such idea but I don't understand how to get a formula or faster solution | IlushaMax | 1023. Пуговицы | 18 янв 2019 12:11 | 3 |
var i,n,l,j:longword; found:boolean; begin readln(n); repeat found:=False; for j:=3 to n div 2 do begin if n mod j=0 then begin found:=True; break; end; end; if found then n:=j; until not found; writeln(n-1); readln; end. Please help me to optimize my code. It's 0.405 sec for j := 3 to sqrt(n) do will help you :) > for j := 3 to sqrt(n) do will help you :) will it? for sqrt(8) = 2.8, but answer should be 4 - 1 = 3 |
| Why Runtime error | Izazul Haque Saad | 1001. Обратный корень | 17 янв 2019 01:46 | 1 |
#include<stdio.h> #include<stdlib.h> #define x 100000 int main() { long long int n , c=0,i; double ar[x] = {}; while(scanf("%lld",&n)){ if(n < 0) break; ar[c++] = n; } for(i=c-1; 0<=i; i--){ printf("%.4lf\n",sqrt(ar[i])); } return 0; } |
| WA 1 Что не так? | Sergo | 1068. Сумма | 16 янв 2019 22:17 | 2 |
var
i, n: integer; c : real; begin read(n); c := 0; if n > 0 then begin for i := 1 to n do c := n; write(c); end; if n <= 0 then begin for i := 1 downto n + 1 do c := (-((-n) * (1 - n) / 2) + 1); write(c); end; end. Доп. примеры/add. examples: n=-5 -5+(-4)+(-3)+(-2)+(-1)+0+1 n=5 5+4+3+2+1 n=0 0+1 Арифмет. прогрессия/arithm. progression |
| give a configuration, is there O(P) sol to judge it has a sol?? | Shen Yang | 1589. Сокобан | 13 янв 2019 12:42 | 2 |
I think the answer is probablye Yes... I think it is relating to the number of inverse pairs of permuation.. |
| Hint.. | esger | 1356. Чего бы попроще | 12 янв 2019 19:52 | 4 |
Be sure that(at least for the given interval, [4,2*10^9]) every even number can be shown as sum of two prime numbers. 1. if n is prime, {n} 2. if n is even, {n = p1 + p2} 3. if n is odd {n = 3 + p1 + p2} ( n-3 is even, so that recall second case.) For convenience, prime numbers under 10^5 can be initialized. Edited by author 03.12.2012 03:00 Edited by author 03.12.2012 03:00 Re: Hint.. Mishail [USU SESC division by zero masters] 21 фев 2013 23:57 If he could proof it, he would get 1 thousand million dollar Edited by author 02.08.2015 20:59 > if n is odd {n = 3 + p1 + p2} ( n-3 is even, so that recall second case.) IMO this is wrong. 85 = 2 + 83 is the counter-case. > For convenience, prime numbers under 10^5 can be initialized. this way too big. :) Edited by author 12.01.2019 19:53 Edited by author 12.01.2019 19:54 |
| No subject | Alexandr_Morozov | | 12 янв 2019 18:24 | 1 |
|
| My code AC with GCC, but WA with G++. Any one help explain it? | some_programming_novice | 1126. Магнитные бури | 12 янв 2019 12:12 | 1 |
Weird. Edited by author 12.01.2019 12:15 |
| WA 22. Give me some tests that may help | Erkebulan | 2033. Девайсы | 11 янв 2019 15:04 | 1 |
|
| Use C and Visual C 2017, Luke | a.menshchikov | 1220. Stacks | 10 янв 2019 18:46 | 1 |
C++ costs 200 kb (Visual C++ and 400 kb other compilers). |
| When will Grand Theft Array VI be released? | BowieD | 2000. Grand Theft Array V | 10 янв 2019 17:20 | 1 |
When do we go from one-dimensional array to two-dimensional? This will be so rad! |
| A better solution | ComebackSeason | 1119. Метро | 9 янв 2019 20:32 | 4 |
I got an AC with dynamic programming and without a graph and I am frustrated with my memory consumption. I used C++ for this and i've got 0,31s and 16000 KB. I guess my solution consumed so much memory because I've stored 2 matrices, one for grid second for diagonales. Matrix[i][j] = min (Matrix[i-1][j]+100, Matrix[i][j-1]+100, Matrix[i-1][j-1] + Diag[i][j]) where Diag[i][j] is either 100 * sqrt(2) or Infinity. I wonder if there is a better solution. I think a simple BFS could give me an answer, Bellman-Ford and Dijkstra's algorithms will give it for sure though. Nevertheless, I've never worked with a graph where every vertex is a 2D point. How should i store it? vector <int> g[maxN][maxN] ? How do I fill it with values efficently? But when Diag[i][j] get infinity sir I think the main cause of memory consumption is the matrix of DOUBLES. Even a simple array of doubles consumes a lot of memory. Even for the solution involving graph and shortest paths would use 'huge' amount of memory, since you would also need a 2 dimensional array of doubles (I suppose). I managed to solve it using 9360KB. Edited by author 14.06.2018 17:45 a better solution is to use dynamic programming to find the longest increasing sequence of diagonals, which there are 100 at most. then ``` min = (n + m - maxDiagonals * 2) * distance + maxDiagonals * diagonalDistance ``` |
| wa #15 | 👑TIMOFEY👑 | 1964. Китайский язык | 8 янв 2019 00:11 | 1 |
wa #15 👑TIMOFEY👑 8 янв 2019 00:11 (yes, somehow I've got wa15) try this test (it helped me to get AC): 10 3 7 7 7 |
| why... this is wrong answer | Iqramul Islam | 1306. Медиана последовательности | 6 янв 2019 11:18 | 1 |
#include <iostream> using namespace std; /// A BST... struct Node { double data; struct Node *left, *right; }; ///function to create new Node in BST struct Node *newNode(double item) { struct Node *temp = new Node; temp->data = item; temp->left = temp->right = NULL; return temp; } ///function to insert a new Node /// with given key in BST struct Node* insert(struct Node *node, double key) { ///if tree is empty, return a new node if(node==NULL) return newNode(key); ///otherwise, recur down the tree.. if(key <node->data) node->left = insert(node->left, key); else if (key >node->data) node->right = insert(node->right, key); return node; }; double counNodes(struct Node *root) { struct Node *current, *pre; double count = 0; if(root==NULL) return count; current=root; while(current!=NULL) { if(current->left==NULL) { count++; current=current->right; } else { pre = current->left; while(pre->right !=NULL && pre->right !=current) pre = pre->right; if(pre->right==NULL) { pre->right=current; current = current->left; } else { pre->right = NULL; count++; current = current->right; } } } return count; } ///Function to find median in o(n) time and O(1) space... double findMedian(struct Node *root) { if(root == NULL) return 0; int count = counNodes(root); int currCount = 0; struct Node *current = root, *pre, *prev; while (current!= NULL) { if(current->left == NULL) { currCount++; ///odd case.. if(count %2 !=0 && currCount == (count+1)/2) return prev->data; ///Even case... else if(count%2==0 && currCount == (count/2)+1) return (prev->data + current->data)/2; ///Update prev..for even no. of nodes... prev = current; current = current->right; } else { ///Find inorder predecessor of current... pre = current->left; while(pre->right!= NULL && pre->right!=current) pre = pre->right; /// make current as right child of in. pre.dec. if(pre->right == NULL) { pre->right = current; current = current->left; } /// revert the changes.. made in if part /// to restore the original tree.. , fix the right chid of predecessor... else { pre->right = NULL; prev = pre; currCount++; if(count%2!=0 && currCount == (count+1)/2) return current->data; else if (count%2!=0 && currCount == (count/2)+1) return (prev->data+current->data)/2; ///Update...for even case... prev = current; current = current->right; } } } } int main() { struct Node *root = NULL; int n; double x; cin >> n; cin >> x; root = insert(root, x); for(int i=1; i<n; i++) { cin >> x; insert(root, x); } //cout << findMedian(root); //if(n%2==0) printf("%.1f", findMedian(root)); } |
| if WA28 | Baurzhan | 1711. Кодовые имена | 5 янв 2019 17:36 | 4 |
if your store data in array of pairs begin loop from zero i=0 not from 1! I had wa28, too my mistake was a incorrect comparison of strings for example s1="bb"; s2="bbbb"; f(s1,s2); // give true s1<s2 f(s2,s1); // give me too true, but this is mistake When I have corrected this i had ac sorry for my english)) Edited by author 11.10.2009 12:23 i get WA28,too. i try your way but it is useless. plz help me! Edited by author 05.01.2019 17:36 |
| easy O(n log m) c++ 0.062 824кб | Viktor Krivoshchekov`~ | 1126. Магнитные бури | 5 янв 2019 16:36 | 1 |
[deleted] Edited by author 21.05.2019 23:17 |
| Some hints | monsky | 1003. Чётность | 4 янв 2019 16:14 | 3 |
Online tests surely contain several tests in one file, so: 1. Be sure clean your dictionaries before every test. 2. Be sure read ALL lines of current test, even you got correct answer before all input was used. This two issues were the reason of my WA1. After fixing them I got "Accepted". Use the following test to validate mentioned above points: 100 5 5 6 odd 7 8 odd 1 6 even 1 4 odd 7 8 even 3 3 1 1 odd 3 3 odd 1 3 odd 5 4 1 2 even 4 5 even 1 5 odd 3 3 even 10 5 1 2 even 3 4 odd 5 6 even 1 6 even 7 10 odd 20 8 1 9 odd 10 17 odd 18 26 odd 4 5 odd 27 40 even 21 40 odd 1 20 odd 10 20 odd 200 8 1 9 odd 10 17 odd 18 26 odd 4 5 odd 27 40 even 21 40 odd 1 20 odd 10 20 odd -1 Answer: 4 3 3 3 2 6 Why 6th answer is 2 rather than 6? |
| Для wa7 | a2ch | 1205. На метро или пешком? | 3 янв 2019 10:16 | 1 |
Спасибо парню из предыдущей ветки,лично мне это реально помогло Короче смысл в том,что в 7 тесте либо координаты A совпадают с координатами какой-нибудь станции (или тоже самое с B),либо у нескольких станций одинаковые координаты. Ну и прикол в том,что если вы строите матрицу смежности,то он будет считать что там нет пути, 0 же стоит |
| C++ AC | D4nick | 2031. Числа-перевёртыши | 3 янв 2019 06:56 | 1 |
C++ AC D4nick 3 янв 2019 06:56 the main difficulty here was to understand that you need to use <string> #include <iostream> #include <string> using namespace std; int main() { int n; string arr[4] = { "16", "06", "68", "88" }; cin >> n; if (n <= 4) for (int i = 0; i < n; i++) { cout << arr[i] << " "; } else cout << "Glupenky Pierre"; } |
| 2 Judges: TEST ARE WRONG!!! Here is a prove... (+) | Akshin Salimov | 1118. Нетривиальные числа | 31 дек 2018 14:35 | 9 |
Judjes tell me after you read my message, I will delete an AC program.
Here is th 1st program it got WA#3: [Program was deleted by author, beacuse it got AC =)] [Thx Vladimir! Judges if you need it, I can post it.] Here is 2nd program it got AC: [Program was deleted by author] [Judges if you need it, I can post that code for a while] Here is one test: 318 330 Correct answer is 323 (Triviality(323)=0.114551) AC programs answer for this tests was : 324 (Triviality(324)=1.619195) It means that AC program gave incorrect answer, but program which got WA#3 gave correct answer!!! It's shameful!!! Edited by author 20.01.2006 20:49 Edited by author 21.01.2006 02:45 What can you say about program which got wa? How can you make it to get AC? Your mistake is that you forget to add line prime:=true; in the end of prime(x) function AC!!! Akshin Salimov 21 янв 2006 02:40 I got AC!!! Vladimir, Thank you very much! You are genius! Большое человеческое спасибо! My code: [code deleted] I have Time limit exceeded. I need optimal solution of this task. Help me please! Edited by moderator 19.11.2019 23:40 go to the sqrt(b), not to b/2 > go to the sqrt(b), not to b/2 could you help understanding why? for 20 the triviality is `(1+2+4+5+10)/20`, kind of meaning you would need to go to b/2. no? gotcha. you can do (i + N/i), so the N/i bit will make sure you would need to go only up to sqrt(N). thanks |