AtCoder Regular Contest 062

Submission #1364609

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}
 
using i64=int64_t;

void shift(vector<int> &a){
    rotate(a.begin(),a.begin()+1,a.end());
};

void normalize(vector<int>& a){
    auto amin=a;
    rep(i,0,4){
        amin=min(amin,a);
        shift(a);
    }
    a=amin;
}

i64 encode(vector<int>& a){
    i64 res=0;
    rep(i,0,4){
        res*=1000;
        res+=a[i];
    }
    return res;
}

vector<int> reverse(vector<int> &a){
    auto b=a;
    swap(b[0],b[1]);
    swap(b[3],b[2]);
    return b;
}

int f(vector<int>& a){
    if(a[0]==a[1] and a[1]==a[2] and a[2]==a[3]) return 4;
    if(a[0]==a[2] and a[1]==a[3]) return 2;
    return 1;
}

void input(int& N,vector<vector<int>> &C){
    cin >> N;
    C.resize(N);
    rep(i,0,N){
        C[i].resize(4);
        cin >> C[i][0] >> C[i][1] >> C[i][2] >> C[i][3];
        normalize(C[i]);
    }
}

void solve(){
    int N;
    vector<vector<int>> C;
    input(N,C);

    map<i64,i64> count[5]; //1,2,4
    rep(i,0,N) ++count[f(C[i])][encode(C[i])];
 
    auto make_sides=[&](int i,int j){
        vector<vector<int>> sides(4,vector<int>(4));
        rep(k,0,4){
            sides[k][0]=C[i][(k+1)%4];
            sides[k][1]=C[i][k];
            sides[k][2]=C[j][k];
            sides[k][3]=C[j][(k+1)%4];
        }
        return sides;
    };
 
    i64 ans=0;
    rep(i,0,N){
        --count[f(C[i])][encode(C[i])];
        rep(j,i+1,N){
            --count[f(C[j])][encode(C[j])];
            C[j]=reverse(C[j]);
            rep(k,0,4){
                auto sides=make_sides(i,j);
                for(auto &side:sides) normalize(side);
                i64 tmp1=1;
                rep(i_,0,4){
                    i64 tmp2=count[f(sides[i_])][encode(sides[i_])];
                    rep(j_,0,i_) if(encode(sides[j_])==encode(sides[i_])) --tmp2;
                    tmp1*=tmp2*f(sides[i_]);
                }
                ans+=tmp1;
                shift(C[j]);
            }
            C[j]=reverse(C[j]);
            ++count[f(C[j])][encode(C[j])];
        }
    }
    
    cout << ans << endl;
}
 
int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

Submission

Task問題 C - AtCoDeerくんと選挙速報 / AtCoDeer and Election Report
User nameユーザ名 walkre
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 2821 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
Sample - 0_000.txt,0_001.txt,0_002.txt
All 0 / 300 0_000.txt,0_001.txt,0_002.txt,1_003.txt,1_004.txt,1_005.txt,1_006.txt,1_007.txt,1_008.txt,1_009.txt,1_010.txt,1_011.txt,1_012.txt,1_013.txt,1_014.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
0_000.txt WA
0_001.txt WA
0_002.txt WA
1_003.txt WA
1_004.txt WA
1_005.txt WA
1_006.txt WA
1_007.txt WA
1_008.txt WA
1_009.txt WA
1_010.txt WA
1_011.txt WA
1_012.txt WA
1_013.txt WA
1_014.txt WA