제출 #250053

#제출 시각아이디문제언어결과실행 시간메모리
250053MarcoMeijer미술 수업 (IOI13_artclass)C++14
7 / 100
109 ms15096 KiB
#include "artclass.h"
#include <bits/stdc++.h>
using namespace std;

//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()

double c [500][500][3];
double cd[500][500][3];
int dx[]={-1,0,1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,1,-1,-1};
double mult[]={2,2,2,2,1,1,1,1};

int h, w;
bool inside(int x, int y) {return x>=0 && x<h && y>=0 && y<w;}

double examples[4][27] = {{
14968.8, 
8517.3, 
6046.87, 
2228.28, 
1542.86, 
3661.38, 
3068.22, 
3945.73, 
5627.57, 
6715.76, 
6619.95, 
8050.14, 
7332.96, 
7551.7, 
7971.12, 
955.079, 
5285.21, 
10456.4, 
10231.6, 
7303.18, 
11097.2, 
1289.51, 
4803.93, 
12652.7, 
1112.03, 
2135.82, 
1663.29, 
},
{
1863.74, 
2249.91, 
2795.88, 
1098.98, 
991.329, 
1764.39, 
3713.81, 
1131.94, 
1585.1, 
2288.83, 
1271.49, 
1016.72, 
3608.12, 
4070.76, 
2202.34, 
552.871, 
361.696, 
877.492, 
1337.11, 
1842.26, 
1965.81, 
137.16, 
87.8501, 
252.831, 
23.189, 
8.9428, 
8.38442, 
},
{
561.666, 
222.064, 
168.7, 
1810.96, 
1528.12, 
2163.46, 
1130.87, 
1298.87, 
1782.49, 
1319.54, 
1188.81, 
1052.23, 
1368.85, 
1061.6, 
663.857, 
1075.17, 
1062.05, 
633.368, 
2959.96, 
1765.37, 
684.13, 
1145.57, 
720.111, 
186.855, 
121.868, 
74.7885, 
34.0162, 
},
{
134.112, 
4.60749, 
13.4158, 
185.728, 
22.5654, 
9.97318, 
453.825, 
271.306, 
210.62, 
235.882, 
3367.58, 
7097.47, 
1912.29, 
433.348, 
926.524, 
273.41, 
1627.74, 
2039.21, 
3491.69, 
323.028, 
59.1425, 
272.009, 
204.556, 
15.127, 
948.653, 
414.824, 
285.082, 
}};

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
    h=H, w=W;
    RE(i,h) RE(j,w) c[i][j][0] = (double)R[i][j]/255.0;
    RE(i,h) RE(j,w) c[i][j][1] = (double)G[i][j]/255.0;
    RE(i,h) RE(j,w) c[i][j][2] = (double)B[i][j]/255.0;
    RE(x,h) RE(y,w) RE(z,3) {
        cd[x][y][z] = 0;
        RE(d,8) {
            int nx=x+dx[d];
            int ny=y+dy[d];
            if(!inside(nx,ny)) continue;
            double dif = (c[ny][nx][z] - c[x][y][z])*mult[d];
            cd[x][y][z] += dif*dif;
        }
    }

    double values[3];
    RE(z,3) {
        double avg=0;
        RE(x,h) RE(y,w) avg+=cd[x][y][z]*cd[x][y][z];
        avg /= double(h*w);

        double tot=0;
        RE(x,h) RE(y,w) {
            double a = cd[x][y][z]*cd[x][y][z] - avg;
            tot += a*a;
        }
        tot /= double(h*w);
        values[z] = tot;
        //cout<<tot<<", "<<endl;
    }
    
    int ans = 0;
    double closest = INF;
    RE(i,4) {
        RE(j,9) {
            double dist = 0.0;
            RE(k,3) dist += fabs(values[k]-examples[i][j*3+k]);
            if(dist < closest) {
                closest = dist;
                ans = i;
            }
        }
    }
    return ans+1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...