Code Submission Evaluation System Login

HIIT Open 2016

Start:2016-05-28 11:00:00
End:2016-05-28 16:00:00
 

Tasks | Messages | Scoreboard | Statistics


CSES - HIIT Open 2016 - Results
History
2016-05-28 11:24:25
Task:Approximate
Sender:Spitfire
Submission time:2016-05-28 11:24:25
Language:C++
Status:READY
Result:TIME LIMIT EXCEEDED

Test results

testverdicttime (s)
#1TIME LIMIT EXCEEDED-- / 1.00details

Code

#include <iostream>

float handle_query(unsigned int numbers[], unsigned int a, unsigned int b) {
	float avg = 0;
	for (size_t i = a; i <= b; i++) {
		avg += numbers[i];
	}
	avg /= (b-a + 1);

	float err = 0;
	for (size_t i = a; i <= b; i++) {
		err += (numbers[i] - avg) * (numbers[i] - avg);
	}
	err /= (b-a + 1);
	return err;	
}

int main()
{
	std::ios_base::sync_with_stdio(0);
	std::cin.tie(0);

	unsigned int n, q;
	std::cin >> n >> q;

	unsigned int numbers[100000];

	unsigned int nb;
	for (size_t i = 0; i < n; i++) {
		std::cin >> nb;
		numbers[i] = nb;
	}

	unsigned int a,b;
	for (size_t i = 0; i < q; i++) {
		std::cin >> a >> b;
		std::cout <<std::fixed <<  handle_query(numbers, a-1, b-1) << std::endl;
	}

	return 0;
}

Test details

Test 1

Verdict: TIME LIMIT EXCEEDED

input
100000 100000
62 64 35 47 57 38 52 4 56 13 7...
view   save

correct output
831.753342
833.361649
833.847478
834.425131
831.468120
836.550284
840.319891
843.709808
830.097515
832.352323
828.549331
811.748878
833.912525
830.245034
831.485429
815.101051
834.579010
848.833782
839.942329
822.449380
...
view   save

user output
(no output)
view   save