Общий форумLet C = A + '$*&' + B for string C build Palindrom Tree. calculate frequency of each palindrom : f(A,p) calculate frequency of each palindrom : f(B,p) x = count(f(A,p)>f(B,p)) y = count(f(A,p)==f(B,p) && f(A,p)!=0) z = count(f(A,p)<f(B,p)) //little code: freq[i][0] ---> f(A,p); freq[i][1] --> f(B,p). for(int i = 0; i < a.size(); ++i){ add_letter(a[i]); freq[last][0]++;} add_letter('$'); add_letter('*'); add_letter('&'); for(int i = 0; i < b.size(); ++i){ add_letter(b[i]); freq[last][1]++;} for(int z = sz-1; z > 0; z--){ v = link[z]; freq[v][0] += freq[i][0]; freq[v][1] += freq[i][1]; } int x=0,y=0,z=0; for(int i = 2; i< sz; ++i)// skip roots { x += (bool)(freq[i][0] > freq[i][1]); y += (bool)(freq[i][0] == freq[i][1] && freq[i][0] !=0); z += (bool)(freq[i][0] < freq[i][1]); } #include <iostream> #include <string> using namespace std; int main() { int num, res; string c, b = "!", a = "!"; cin >> num >> c; res = num; int sign = 0; for (int i = 1; b <= c; i++) { b = b + a; sign = i; } if (num%sign != 0) { for (int i = 1; i*sign < num; i++) { res = res * (num - i*sign); } res = res *(num%sign); } else { for (int i = 1; i*sign < num; i++) { res = res * (num - i*sign); } } cout << res; return 0; } Solved both tasks with the same algorithm. Think this task is over-valued. Edited by author 26.10.2016 20:59 just submitted code and got TLE on 15test, submitted same code after few minutes and got accepted. submitted again and got TLE on 24test for same code. All solutions have been rejudged with the current time limit. Also, few more tests have been added. 10 authors have got AC while 23 other have lost. I have replaced standart C# input functions with my low level parse method and got Accepted. Is this the goal of that rejudgement? Well, I just resubmitted the previous solution with visual c++. I do every query O(1) operations and use scanf and printf. I think the version of your g++ compiler is not that good. There were some troubles with scanf and printf at some new versions of g++ compiler. source code of algorithm Manaker (find all palindroms in O(n)), where explained in e-maxx.ru is incorrect :), see comments to below of that page. Edited by author 25.10.2016 16:17 it is also not worth than 10000+ rating... I'm getting wrong ans on test case 3. Can someone please give a hint? Here's my solution in Java: FastReader sc = new FastReader(System.in); double a = sc.nextDouble(); double r = sc.nextDouble(); double ans; if (r <= a / 2) { ans = Math.PI * r * r; } else { double angle = (2 * Math.PI) - (8 * Math.acos(a / (2 * r))); ans = (r * r * angle / 2) + (2 * a * Math.sqrt(r * r - a * a / 4)); } System.out.println(String.format("%.3f", ans)); New tests have been added to the problem, all accepted solutions have been rejudged. 490 authors have lost their AC. 47062 Edited by author 17.06.2009 19:29 I also get 47062 and use 1500+ms 85000K in codeforces custom test, how to optimize memory? YES Accepted memory is too hard... Edited by author 23.10.2016 18:54 Edited by author 23.10.2016 18:54 I hope admin can decrease the Time limit to 1s, to encourage me continue to optimise time. Can anyone provide test case for WA#1, please? #include <iostream> #include <cstdlib> #include <string> using namespace std; string S, A; unsigned short An = 1; bool negative = true; void get_next_A(); void get_S(unsigned short); int main() { unsigned short input_n; cin >> input_n; get_S(input_n); cout << S << endl; return 0; } void get_next_A() { if(An == 1) A = "sin(1)"; else { A.erase(A.size() - An + 1, An); if(negative) A += "-sin("; else A += "+sin("; char buffer[5]; itoa(An, buffer, 10); A += buffer; for(unsigned short j = 0; j < An; ++j) A += ")"; negative = !negative; } ++An; return; } void get_S(unsigned short n) { char _buffer[10]; for(unsigned short i = 0; i < n - 1; ++i) S += '('; for(unsigned short i = n; i > 0; --i) { get_next_A(); itoa(i, _buffer, 10); S += A; S += '+'; S += _buffer; if(i != 1) S += ')'; } return; } You can make it simpler :) For example, here is the function generating sine expressions: string get_sine_expression(int x, int n) { if (x == n) return "sin(" + to_string(x) + ")"; char sign = x & 1 ? '-' : '+'; return "sin(" + to_string(x) + sign + get_sine_expression(x + 1, n) + ")"; } #include <iostream> using namespace std; int main() { int n,res=0; cin >> n; if (n < 0) { n = n*-1; int *arr; arr = new int[n+2]; arr[0] = 1; for (int i = 1; i < n+2; i++) { arr[i] = arr[i - 1] - 1; } for (int i = 0; i < n+2; i++) { res = res + arr[i]; } cout << res; } else if(){ int *arr; arr = new int[n]; arr[0] = 1; for (int i = 1; i < n; i++) { arr[i] = arr[i - 1] + 1; } for (int i = 0; i < n; i++) { res = res + arr[i]; } cout << res; } return 0; } n = n*-1; ? arr[i] = arr[i - 1] - 1; ? -10000.....-1 0 1 program Suma; var a,b,e:integer; begin read(a); b:=1; if a<0 then e:=((1+a) div 2)*(((a-1)div((b-1)-1))+1) else e:=(a*(a+1)) div 2; writeln(e); end. Check for N = 0. import java.util.Scanner; public class P { public static void main(String[] args) { Scanner input = new Scanner(System.in); int a = input.nextInt(); int b = 1; if (a>-10000) if (a < 10000) { if (a >= 1) { int e = (a * (a + 1)) / 2; System.out.println(e); } if (a <= -1) { int d = ((1 + a) / 2) * ((a - 1) / ((b - 1) - 1) + 1); System.out.println(d); } if (a<1) if (a>-1) { System.out.print(a+1); } } } } я уже всё зделал, что они просили. И всё равно не идёт( Edited by author 21.10.2016 18:08 Edited by author 21.10.2016 18:37 check 2. Prints reply twice. Edited by author 21.10.2016 18:47 Edited by author 21.10.2016 18:52 var i,n,q,h:integer; k:real; begin q:=0; read(n); h:= 10000; if (n <= h) and (n >= -h) then begin if n>0 then begin k:= ((1+n)/2)*n; writeln(k); end; if n=0 then begin k:=0+1; writeln(k); end;
if n<0 then begin for i:= 1 downto n do inc(q); k:= ((1+n)/2)*q; writeln (k); end; end; end. формула для від'ємних чисел не підходить там така має бути(по моєму): ((1 + a) / 2) * ((a - 1) / ((b - 1) - 1) + 1) Edited by author 21.10.2016 16:59 I tried binary search, harsh table, got TLE. then I thought using direct mapping table could get MLE, but never TLE, so i tried it, still TLE!!!tell me how could this code get TLE. #include <iostream> using namespace std; char a[1000000001]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { int j; cin >> j; a[j] = 1; } int m; cin >> m; int cnt= 0; for (int i = 1; i <= m; ++i) { int j; cin >> j; cnt += a[j]; } cout << cnt; } To start with, 1 billion might be a bit too huge of a number. Try 3 zeroes less maybe. Insert this string: int main() { ios::sync_with_stdio(false); // It will speed up reading process } It doesn't (significantly) speed up Visual C++, as for me. Using C-style IO (printf/scanf) is more predictable. |
|