2
1
Fork 0
aoc2021/09/solution.c
2021-12-09 10:16:11 +01:00

54 lines
2.5 KiB
C

#include <stdio.h>
// // // /
// /// /// /// /// /// /
// /// /// / // /// /// /
// // // // /
// /// // // /// /// / /
// /// // /// // / /
// /// / // /// /// /// /
// // // /
// /// /// /// /// /
// /// /// /// /// // /
// /// /// /// /// /// / /
// / /// /// /// /// /
// / // /// /// /
///////// ///// //////
// /// / // /// /
/////////// /////
// /// /// /// /
//////////////////
/// /// /// /// /
/////////////////
/// //////// ///
// /////// ////
/// // /////
/// ///////
//// ////
///////////
///////
//////
///
char
m[100
#define\
M(a, b) ((\
a)<(b)?(a):(b))
#define D(I,J) {v\
=m[ I][J];if(v!=9&&v>\
p&&!V[I][J])z+=d(I,J);}
][101]={0},V [100][100]={
0},p;int d(int i,int j){int
z=1;char v,p =m[i][j];V[i][j]=1
;if(i )D(i-1,j )if(i<99)D(i+1 ,j)if
(j)D(i,j-1 )if(j<99 )D(i ,j+1)return z;}int
main(){int i,j,k,l ,b,S= 0,t[3]={0}; for
( i=0;i<100 ;i++){scanf("%s" ,(char*)&m[i]);for
(j=0;j<100 ;j++)m [i][j]-='0' ;}for(i=0;i<100
;i++){for (j=0;j<100;j++){p=m[ i][j];if((i&&m[i
-1][j]<=p)||(i<99&&m[i+1][j]<=p)||(j&&m[i][j-1]<=p) ||
(j<99&&m[i][j+1]<=p))continue ;S+=p+1;b=d(i,j);l=M(t[0],
M(t[1 ],t[2]));if(b>l)for (k =0;k<3;k++)if(t[k]==l){t[k]
=b;break;}}}printf("Silver: %d\nGold: %d\n",S,t[0]*t[1]*t[2]);}