Codeforces Round #293 (Div. 2)

Source: Internet
Author: User

A

Simple questions

B

Simple questions

C

Simple questions

D

Simple expectations

E

The minimum sum (|a[i]|) causes a new sequence of the sum of each successive K a[i] to be monotonically increasing

Apparently A[i]<a[i+k]<a[i+2*k]<a[i+3*k]

Find a continuous? And left end and right end greedy can

#include <cstdio> #include <cstring> #include <cstdlib>typedef __int64 ll;int a[100010], b[100010], c[ 100010];int N, m;bool cal (int s, int e, int k) {if (S < 1 && e > N) {int x = (e-k)/m;int y =-x/2;for (int i = k) ; I <= N; i + = m) a[i] = y++;} else if (S >= 1 && e > N) {int x = (e-s)/m-1;int y =-x/2;if (A[s] >=-x/2) y = a[s]+1;for (int i = s+m; I &lt ; = N; i + = m) a[i] = y++;} else if (S < 1 && e <= n) {int x = (e-k)/m;int y = x/2;if (a[e] <= x/2) y = a[e]-1;for (int i = e-m; I >= K ; I-= m) {A[i] = y--;}} Else{int x = (e-s)/m-1;  ll tmp = (ll) a[e]-(LL) a[s]-1;if (TMP < x) return false;int y1 =-x/2;int y2 = x/2;if (A[s] >=-x/2) {y1 = a[s]+1;for (int i = s+m; I < E; i + = m) a[i] = y1++;} else if (A[e] <= x/2) {y1 = a[e]-1;for (int i = e-m; i > S; i-= m) a[i] = y1--;} else{for (int i = s+m; i < e; i + = m) a[i] = y1++;}} return true;} int main () {scanf ("%d%d", &n, &m), for (int i = 1; I <= n; i++) {char s[22];scanf ("%s", s); if (S[0] = = '? ') B[i] = 1;elsea[i] = atoi (s);} int flag = 0;for (int i = 1; I <= m; i++) {int t = 0;for (int j = i; J <= N; j + = m) {if (!b[j]) T = j;while (j <= N &am p;& B[j]) J + = M;if (T < j) {if (!cal (t, J, i)) {flag = 1;break;}} if (j <= N) t = j;} for (int j = i+m; J <= N; j + = m) {if (A[j] <= a[j-m]) {flag = 1;break;}} if (flag) break;} if (!flag) {for (int i = 1; I <= n; i++) printf ("%d", A[i]);p UTS (""); elseprintf ("Incorrect sequence\n"); return 0;}


Codeforces Round #293 (Div. 2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.