Submission #1076031

#TimeUsernameProblemLanguageResultExecution timeMemory
1076031TheQuantiX미술 수업 (IOI13_artclass)C++17
29 / 100
45 ms6060 KiB
#include <bits/stdc++.h>
#include "artclass.h"

using namespace std;

vector<float> vecs[4] = {{1.2164, 0.892524, 0.864051, 0.2294985}, {1.17065, 1.15617, 0.669768, 0.346205}, {1.13886, 1.00498, 0.855663, 0.54235}, {1.38868, 1.00333, 0.608068, 0.092916}};

vector<float> vectorize(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
    vector<float> ans;
    float r = 0, g = 0, b = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if ((R[i][j] + G[i][j] + B[i][j]) == 0) {
                continue;
            }
            r += (float)R[i][j] * 3. / (R[i][j] + G[i][j] + B[i][j]);
            g += (float)G[i][j] * 3. / (R[i][j] + G[i][j] + B[i][j]);
            b += (float)B[i][j] * 3. / (R[i][j] + G[i][j] + B[i][j]);
        }
    }
    r /= H * W;
    g /= H * W;
    b /= H * W;
    ans.push_back(r);
    ans.push_back(g);
    ans.push_back(b);
    float d = 0;
    for (int i = 0; i < H - 1; i++) {
        for (int j = 0; j < W; j++) {
            // if ((R[i][j] + G[i][j] + B[i][j]) == 0) {
            //     continue;
            // }
            d += abs(R[i + 1][j] - R[i][j]) / 255.;
            d += abs(G[i + 1][j] - G[i][j]) / 255.;
            d += abs(B[i + 1][j] - B[i][j]) / 255.;
        }
    }
    // cout << d << endl;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W - 1; j++) {
            // if ((R[i][j] + G[i][j] + B[i][j]) == 0) {
            //     continue;
            // }
            d += abs(R[i][j + 1] - R[i][j]) / 255.;
            d += abs(G[i][j + 1] - G[i][j]) / 255.;
            d += abs(B[i][j + 1] - B[i][j]) / 255.;
        }
    }
    // cout << d << endl;
    d /= H * W * 2;
    ans.push_back(d);
    return ans;
}

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
    auto fl = vectorize(H, W, R, G, B);
    array<float, 4> diffsq = {0, 0, 0, 0};
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < fl.size(); j++) {
            diffsq[i] += (fl[j] - vecs[i][j]) * (fl[j] - vecs[i][j]);
        }
    }
    return min_element(diffsq.begin(), diffsq.end()) - diffsq.begin() + 1;
}

Compilation message (stderr)

artclass.cpp: In function 'int style(int, int, int (*)[500], int (*)[500], int (*)[500])':
artclass.cpp:59:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<float>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for (int j = 0; j < fl.size(); j++) {
      |                         ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...