Общий форум[code deleted] Edited by moderator 19.11.2019 23:13 check 1 a aa aaa answer a undefined aa undefined aaa undefined It looks as first input number (sequence length) isn't needed for solution. int a[10]={-1,1,2,2,1,-1,-2,-2,-1,1}; ... for(i=1;i<=8;i++) if(x+a[i-1]>0 && x+a[i-1]<9 && y+a[i+1]>0 && y+a[i+1]<9) h++; DO IT!!! :) 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 |
|