Common Boardhello i have problem with my code and i dont know where is it T_T here is my code : var a:real; i,k:integer; z:array[1..100]of real; begin k:=1; while not eof do begin read(a); z[k]:=sqrt(a); k:=k+1; end; for i:=k-1 downto 1 do begin writeln(z[i]:0:4); end; end. Noise() - is constant, or linear, trigonometric, or random function??? #include <iostream> #include <stdio.h> #include <memory.h> #define NMAX 37 using namespace std; long cnt[NMAX]; int n; void genSum(int k, int sum); int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); ///freopen("output.txt", "wt", stdout); #endif scanf("%d", &n); genSum (0 , 0); int answer = 0; for (int it = 9 * n / 2; it >= 0; --it) { answer += cnt[it] * cnt[it]; } printf("%d\n", answer); return 0; } void genSum(int k, int sum) { if (k == n / 2) { ++cnt[ sum ]; } else for (int digit = 0; digit <= 9; ++digit) { genSum(k + 1, sum + digit); } } My code is giving WA on test1. But it is giving correct ans for all these:- 50000 300 300 422791438 49999 299 299 505277419 25000 269 222 716603086 Can anyone provide more test cases? 24124 131 232 373638552 18000 234 279 653833015 34000 98 162 688357676 13452 134 245 900436780 10306 299 207 85275311 2 1 10 My output is: 2 1 2 2 2 2 2 2 2 2 2 Is this corret or Did I understand task wrong..? Please, Also tell me Test #5,6 Edited by author 14.09.2015 18:16 Други, кто-нибудь знает что это за несчастный тест? Проверил программу ВРУЧНУЮ в экселе для всех 50 значений "n", и всё сошлось. What's the problem? [code deleted] Edited by moderator 19.11.2019 22:58 Edited by author 17.01.2017 16:15 WA#10 s == t Edited by author 18.01.2017 00:46 AC! Hell yeah! Can you give me test №76? I'm not getting the bug in the code :(. It would be helpful if someone pointed the mistake. key = {'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 } while True: n = raw_input() if(int(n) == -1): break l = int(raw_input()) d = {} ans = [] for a0 in xrange(l): temp = raw_input() d["".join([str(key[i]) for i in temp])] = temp i = len(n) while(i>0): if n[0:i] in d.keys(): ans.append(d[n[0:i]]) n = n[i:] i = len(n)+1 i-=1 print "No solution." if len(n) != 0 else " ".join(ans) 43550 // hello 3 hell he llo -1 Народ, кто может указать на часть моего кода которая тормозит алгоритм? Чистил как мог, не смог выйти за 0.125 секунд import java.util.Scanner; public class Timus { public static void main (String[] args) { Scanner in = new Scanner(System.in);
byte m = in.nextByte(), n = in.nextByte();
System.out.println( (m*n-1)%2==0 ? "[second]=:]" : "[:=[first]");
in.close();
} } Всё нормально, просто джава медленная. Вон у вас задача a+b за 0.109. Спасибо за пояснение;) а каким же образом люди в топе выходят за 0.05 секунд? Вон первое место в А+B аж за 0.015 работает! Наверняка люди обходят стороной медленные методы и операции. Может вы знаете ресурс где можно почитать об этом? Поиск в гугле ни привёл ни к чем К сожалению, не могу сказать точно. Тут есть несколько моментов. Во-первых, более ранняя джава была быстрее, что можно увидеть по тому, что в основном большинство сабмитов, где указано java 1.5 / java 1.6, быстрее, чем те, в которых java 1.8. Конечно, этот сабмит а+б за 0.015 как раз на джаве 1.8, для меня это конечно странно. Может в коде в опциях был выставлен какой-то ключ для использования более ранней версии или типа того... Во-вторых, "общий" совет, который я могу дать — используйте BufferedReader (и если надо, StreamTokenizer) вместо Scanner'a, потому что последний в джаве обычно медленнее. (см. также код внизу страницы http://acm.timus.ru/help.aspx?topic=java&locale=ru). Хотя, конечно, для программ с маленьким объёмом входных данных разница не должна быть сильно критичной, но там где надо считывать со входа мегабайты — она очень ощутима. If the matrix size is 3, with the given contraints, it won't be "2 special cells", because 8 of them will be walls, and will be only one free cell. Could be that those special cells were located at the same place? Please drop some light on that. Thanks looks like someone has found a special case here ;) either 3x4 or 4x3 has two points, 3x3 does not using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program { static void Main(string[] args) { int k; int n; do { do{ n = int.Parse(Console.ReadLine()); } while (!(n >= 2)); do { k = int.Parse(Console.ReadLine()); } while (!(k >= 2 && k <= 10)); } while (!(n + k <= 18)); int start = (int)Math.Pow(10, n - 1); int end = 0; int check = start; int BigCount = 0; for (int i = n - 1; i >= 0; i--) end += (k - 1) * (int)Math.Pow(10, i); int h = end - start + 1; int o = 0; for (int l = 0; l < n; l++) { o += h % 10 * (int)Math.Pow(k, l); h = h / 10; } for (int i = 0; i < o; i++) { int count = 0; double p = check; for (int j = 0; j < n / 2; j++) { if ((p % 10 + p / 10 % 10) > 0) count++; p = p / 100; } if (count != 0) BigCount++; check++; count = 0; p = check; int r = 0; int m = 0; for (int l = 0; l < n; l++) { if (p % 10 == k) { count++; m += (10 - k) * (int)Math.Pow(10, l); r = 10 - k; } p += r; p = (int)p / 10; } check += m; } Console.Write(BigCount); } } Норм решение? Edited by author 16.01.2017 04:29 Edited by author 16.01.2017 04:30 This is my code: #include <iostream> #include <cmath> using namespace std; int main() { int a[101], n, x, dis1 = 0, dis2 = 0, lb, rb; bool flag = false, flag2 = false;
cin >> n >> x;
if ((x == 0)) flag2 = true; else { if ( n == 0 ) flag = true; }
for ( int i = 0; i < n; i++ ) { cin >> a[i]; if ( (x > 0) && (a[i] < x) && (a[i] > 0) ) flag = true; if ( (x < 0) && (a[i] > x) && (a[i] < 0) ) flag = true; }
if (flag) cout << "Impossible" << endl; else { lb = a[0]; rb = a[0]; for ( int i = 1; i < n; i++ ) { if ( (a[i] > 0) && (a[i] > rb) && (a[i] > x) ) rb = a[i];
if ( (a[i] < 0) && (abs(a[i]) < abs(lb)) && (a[i] < x) ) lb = a[i]; }
if ( x > 0 ) { dis1 = x; dis2 = (int) abs(2*lb) + x; } else { dis1 = 2*rb + (int) abs(x); dis2 = (int) abs(x); }
if (flag2) cout << "0 0" << endl; else cout << dis1 << " " << dis2 << endl; }
system("PAUSE"); return 0; } --------------------------- I can't understand WHY WA#4 Please, help!!! It's too hard code. The real solution is much easier/ My Code perfect AC with Visual Studio 2013, G++ 4.9, G++ 4.9 C++11. But Clang 3.5 gives output limit exceeded, or access violation.... Submit codes 7217044 7217043 Some bugs in the validator were fixed. The problem was rejudged. 299 WA submits turned to AC and 84 AC submits turned to WA. If you will find new bugs, please, write to timus_support (at) acm.timus.ru. Edited by author 09.09.2010 10:57 To those who have WA at 2 after rejudge: The ending point MUST have positive (STRICTLY) coordinates. Try this testcase: 1 1 1 2 2 4 2 3 to see if your answer satisfies the condition. Thx a LOOOOT of @198808xc. I got AC . if c0 less than all of other delay times: x = 0.003 ; y = sqrt(L*L - x*x)
using namespace std; int main() { int n, d[13]; scanf("%d", &n); d[0] = 5; d[1] = 21; d[2] = 12; d[3] = 2; d[4] = 1; d[5] = 4; d[6] = 6; d[7] = 1; d[8] = 4; d[9] = 4; d[10] = 1; d[11] = 0; d[12] = 1; d[13] = 1; printf("%d", d[n]); return 0; } #include <iostream> #include <cmath> #include <cstdlib> #include <cstdio> #include <algorithm> #include <queue> #define f first #define s second #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define ppb pop_back #define mp make_pair #define sz(x) (int) x.size() #define all(x) x.begin(), x.end() #define bit(x) __builtin_popcountll(x) #define sqr(x) ((x) * 1LL * (x)) #define nl '\n' #define ioi exit(0); #define NeedForSpeed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define _7day "IOI2017" using namespace std; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef pair <ld, ld> pdd; typedef pair <ll, ull> hack; const int N = 1e5 + 7, MxN = 1e6 + 7, mod = 1e9 + 7, inf = 1e9 + 7; const long long linf = (ll)1e18 + 7; const long double eps = 1e-15, pi = 3.141592; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; int n, x; priority_queue <unsigned int> q; int main(){ #ifndef _7day freopen (_7day".in", "r", stdin); freopen (_7day".out", "w", stdout); #endif cin >> n; for (int i = 1; i <= n / 2 + 1; ++i) cin >> x, q.push(x); for (int i = n / 2 + 2; i <= n; ++i){ cin >> x; if (x < q.top()) q.pop(), q.push(x); } if (n % 2) printf ("%d.0", q.top()); else{ unsigned int top1 = q.top(); q.pop(); if ((top1 + q.top()) % 2 == 0) cout << top1 / 2 + q.top() / 2 << ".0"; else cout << top1 / 2 + q.top() / 2 << ".5"; } ioi } Edited by author 01.12.2016 20:51 Edited by author 01.12.2016 20:51 Priority queue is based on vector. When vector resizes, 2 data blocks can be allocated in one time. Let it resizes at n/2 size/capacity. Next data block capacity (assuming resize factor 1.5) is 3n/4. Even second block can cause MLE. Both blocks size is 5*n/4 - MLE. You should avoid resizing. You should better set fixed vector size (approx n/2+2) and use heap functions over it. Please can you show, how it can be done. I can't do it Edited by author 03.12.2016 14:16 I tried to do like this but whatever it's got MLE 7 vector <unsigned int> vec; vec.reserve(n / 2 + 2); priority_queue <unsigned int> q (less<unsigned int>(), vec); Google std::make_heap / std::push_heap / std::pop_heap Don't use priority queue at all std::nth_element. but need a little tricky for n <= 2*10^5 --> read all numbers and use direct nth_element (or your own implementation of Kth order statistics). for n > 2*10^5 --> read only 2*10^5 numbers and use nth_element for n - 2*10^5, and remove first n - 2*10^5, i.e. rewrite remain numbers to first n-2*10^5, and again use nth_element for n/2 - (n- 2*10^5) Good Luck!!! I see you got AC, but this description looks suspicious anyway. Let we need to process 9 elements [1,2,3,4,5,6,7,8,9] in any order (so expected answer is 5), and have 5 elements array. As I understand steps should be: for n > 5 --> (1)read only 5 numbers and use nth_element for n - 5, (2) remove first n - 5, i.e. rewrite remain numbers to 5, (3) again use nth_element for n/2 - (n- 5) Am I correct? Let see numbers in order [1,2,5,8,9,3,4,6,7] Read first 5, find (9-5) = 4th: [1,2,5,8,9] => 9 (or 8), rest removed. 5 removed, wont be answer, fail Could you please show your code? #include<stdio.h> int main(void){ int a, b; scanf("%d %d", &a, &b); if(a%2==0 || b%2!=0) puts("yes"); else if(a%2!=0 || b%2==0) puts("no"); return 0; } else puts("no"); is enough Who know O(H*W) or, O(H*W*5) algo ??? С 20 не проходит 15 тест!!! |
|