Submission #446902

# Submission time Handle Problem Language Result Execution time Memory
446902 2021-07-23T18:05:52 Z rainboy Kvalitetni (COCI16_kvalitetni) C
60 / 120
3 ms 844 KB
#include <stdio.h>
#include <string.h>

#define N	1000000
#define K	50

double min(double a, double b) { return a < b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

void sort(int *aa, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, a = aa[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (aa[j] == a)
				j++;
			else if (aa[j] < a) {
				tmp = aa[i], aa[i] = aa[j], aa[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = aa[j], aa[j] = aa[k], aa[k] = tmp;
			}
		sort(aa, l, i);
		l = k;
	}
}

char cc[N + 1]; int zz[K + 1];

double solve(char *cc, int n, int *j_) {
	int aa[K];
	int h, i, j, k, add;
	double sum, prod;

	if (cc[1] == '?') {
		*j_ = 3;
		return zz[1];
	}
	add = -1;
	for (i = 1, k = 0; i < n && cc[i] == '('; i += j + 1) {
		aa[k++] = solve(cc + i, n - i, &j);
		if (add == -1)
			add = cc[i + j] == '+';
	}
	*j_ = i;
	if (add == 1) {
		sum = 0;
		for (h = 0; h < k; h++)
			sum += aa[h];
		return min(sum, zz[k]);
	} else {
		sort(aa, 0, k);
		sum = 0, prod = 1;
		for (h = 0; h < k; h++) {
			if (sum + aa[h] * (k - h) >= zz[k]) {
				double a = (double) (zz[k] - sum) / (k - h);

				while (h < k)
					prod *= a, h++;
				return prod;
			}
			sum += aa[h], prod *= aa[h];
		}
		return prod;
	}
}

int main() {
	int n, k, h;

	scanf("%d", &k);
	for (h = 1; h <= k; h++)
		scanf("%d", &zz[h]);
	scanf("%s", cc), n = strlen(cc);
	printf("%.6f\n", solve(cc, n, &h));
	return 0;
}

Compilation message

kvalitetni.c: In function 'main':
kvalitetni.c:77:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |  scanf("%d", &k);
      |  ^~~~~~~~~~~~~~~
kvalitetni.c:79:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |   scanf("%d", &zz[h]);
      |   ^~~~~~~~~~~~~~~~~~~
kvalitetni.c:80:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |  scanf("%s", cc), n = strlen(cc);
      |  ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 844 KB Output is correct