Created
July 13, 2014 21:33
-
-
Save primenumber/67b70caa3e245f1e416e to your computer and use it in GitHub Desktop.
ICPC Japan Domestic 2014 B
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() { | |
while(1){ | |
int h; | |
cin>>h; | |
if(!h)break; | |
vector<vector<int>> t(h,vector<int>(5)); | |
REP(i,h)REP(j,5)cin>>t[i][j]; | |
int pt=0; | |
while(1){ | |
bool ch=false; | |
REP(i,h){ | |
int len=1; | |
REP(j,4){ | |
if(t[i][j]==t[i][j+1]){ | |
len++; | |
}else{ | |
if(len >= 3 && t[i][j]!=0){ | |
pt+=len*(t[i][j]); | |
REP(k,len){ | |
t[i][j-k]=0; | |
} | |
ch=true; | |
} | |
len=1; | |
} | |
} | |
if(len >= 3 && t[i][4]!=0){ | |
pt+=len*(t[i][4]); | |
REP(k,len){ | |
t[i][4-k]=0; | |
} | |
ch=true; | |
} | |
} | |
if(!ch)break; | |
REP(i,5){ | |
for(int j=h-1;j>=0;--j){ | |
for(int k=j+1;k<h;++k){ | |
if(t[k][i]==0){ | |
swap(t[k][i],t[k-1][i]); | |
} | |
} | |
} | |
} | |
} | |
cout<<pt<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment