AtCoder Grand Contest 026
Tasks - AtCoder Grand Contest 026
結果はA問題まで解くことができました。B問題をずっと考えていたんですが、全く分かりませんでした。まあ、初心者だしね。
A - Colorful Slimes 2
唯一解けた問題です。
先頭からスライムを二つずつ調べていき、同じ色となるスライムの後ろの方を余っている色で塗ります。冗長なコードになっていますが、正解したの良かったです。
コード
import java.util.Scanner; public class ProblemA { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int []a = new int[N]; for(int i = 0; i < N; i++) { a[i] = scan.nextInt(); } scan.close(); int cnt = 0; for(int i = 0; i < N - 1; i++) { if(a[i] == a[i + 1]) { cnt ++; a[i + 1] = 10000 - i; } } System.out.println(cnt); } }