Общий форумHi there! I'm curious regarding submission metrics time and memory. Is this the avg time and avg memory of all the tests or maximum time and maximum memory used in the worst test? Can anybody please reveal how does the system count time and memory for different languages? I would like to reproduce it locally before the submission. I use golang. Thanks 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)); } } } 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 #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; } 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 I think the answer is probablye Yes... I think it is relating to the number of inverse pairs of permuation.. 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 prove it :) 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 Weird. Edited by author 12.01.2019 12:15 C++ costs 200 kb (Visual C++ and 400 kb other compilers). When do we go from one-dimensional array to two-dimensional? This will be so rad! 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 ``` (yes, somehow I've got wa15) try this test (it helped me to get AC): 10 3 7 7 7 #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 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 [deleted] Edited by author 21.05.2019 23:17 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? Спасибо парню из предыдущей ветки,лично мне это реально помогло Короче смысл в том,что в 7 тесте либо координаты A совпадают с координатами какой-нибудь станции (или тоже самое с B),либо у нескольких станций одинаковые координаты. Ну и прикол в том,что если вы строите матрицу смежности,то он будет считать что там нет пути, 0 же стоит 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"; } |
|