제출 #658328

#제출 시각아이디문제언어결과실행 시간메모리
658328cristi_aArt Class (IOI13_artclass)C++17
96 / 100
61 ms3284 KiB
#include <bits/stdc++.h>
#include "artclass.h"
using namespace std;

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
    static const int dx[] = {0, 0, -1, 1};
    static const int dy[] = {1, -1, 0, 0};
    static const int area = H * W;

    auto in = [&](int a, int b) {
        if(a < 0 or a >= H or b < 0 or b >= W) return false;
        return true;
    };

    int red_sum = 0;
    int green_sum = 0;
    int blue_sum = 0;

    int salt_and_pepper = 0;

    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++) {
            red_sum += R[i][j];
            green_sum += G[i][j];
            blue_sum += B[i][j];
            for(int k=0; k<4; k++) {
                int ni = i + dx[k];
                int nj = j + dy[k];
                if(!in(ni, nj)) continue;

                int difs =  abs(R[i][j] - R[ni][nj]) +
                            abs(G[i][j] - G[ni][nj]) +
                            abs(B[i][j] - B[ni][nj]);
                if(difs >= 140) salt_and_pepper++;
            }
        }
    double snp_percent = 1.00 * salt_and_pepper / (2.00 * area) * 100.00;

    double red_avg = 1.00 * red_sum / (1.00 * area);
    double blue_avg = 1.00 * blue_sum / (1.00 * area);
    double green_avg = 1.00 * green_sum / (1.00 * area);
    double green_diff_sum = (green_avg - blue_avg) + (green_avg - red_avg);

    if(snp_percent <= 0.60) return 4;
    if(snp_percent >= 27.00) return 3;
    if(green_diff_sum >= 17 and snp_percent <= 14.00) return 2;
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...