Cod sursa(job #1253822)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 1 noiembrie 2014 20:48:47
Problema Koba Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.03 kb
#include<fstream>
using namespace std;
int n, a, b, c, x, m, t1, t2, t3, i, d, j;
long long sum, s;
int v[1000], f[100000];
ifstream fin("koba.in");
ofstream fout("koba.out");
int main(){
	fin>> n >> t1 >> t2 >> t3;
	a = t1 % 10;
	b = t2 % 10;
	c = t3 % 10;
	x = a * 100 + b * 10 + c;
	v[x] = 1;
	f[1] = x;
	d = (a * b + c) % 10;
	x = b * 100 + c * 10 + d;
	v[x] = 2;
	s = a + b + c + d;
	f[2] = x;
	for(i = 3; i <= n; i++){
		a = b;
		b = c;
		c = d;
		d = (a * b + c) % 10;
		s += d;
		x = b * 100 + c * 10 + d;
		f[i] = x;
		if(v[x] != 0){
			break;
		}
		else{
			v[x] = i;
		}
	}
	s-= (x / 100 + x / 10 % 10 + x % 10);
	m = i - v[x];
	for(j = v[x] + 1; j <= i; j++){
		sum += f[j] % 10;
	}
	n -= (i-1);
	s += (n / m) * sum;
	if(n % m >= 3){
		s += x / 100 + x / 10 % 10 + x % 10;
		for(j = v[x] + 1; j <= n % m + v[x] - 3; j++){
			s += f[j] % 10;
		}
	}
	else{
		if(n%m == 1){
			s += x / 100;
		}
		else{
			if(n % m == 2){
				s += x / 100 + x / 10 % 10;
			}
		}
	}
	fout<< s;
	return 0;
}