Cod sursă (job #578958)

Utilizator avatar GheorgheB Balamatiuc Gheorghe GheorgheB IP ascuns
Problemă Beculețe (clasele 9-10) Compilator cpp-32 | 0,69 kb
Rundă Arhiva de probleme Status evaluat
Dată 20 ian. 2021 20:55:07 Scor 0
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("beculete.in");
ofstream fout("beculete.out");
int main(){
	int N, D, L, C, V;
	fin>>N>>D;
	int a[N+1][N+1];
	for(int i=1;i<=D;i++){
		fin>>L>>C>>V;
		a[L][C]=V+2;
	}
	a[1][1]=1;
	for(int i=2;i<=N;i++)
		for(int j=1;j<=i;j++){
		if(a[i][j]!=2 && a[i][j]!=3){
			if((j==1 && (a[i-1][j]==1 || a[i-1][j]==3)) || (j==i && (a[i-1][j-1]==0 || a[i-1][j-1]==2)))
				a[i][j]=1;
			else 
				if(((a[i-1][j-1]==0 || a[i-1][j-1]==2) && (a[i-1][j]==1 || a[i-1][j]==3)) || ((a[i-1][j-1]==1 || a[i-1][j-1]==3) && (a[i-1][j]==0 || a[i-1][j]==2)))
					a[i][j]=1;
		}
	}
	int k=1;
	for(k=1;k<=N;k++)
		fout<<a[N][k]<<" ";
}