結果

問題 No.1773 Love Triangle
ユーザー kazu0x17kazu0x17
提出日時 2022-08-28 13:12:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 4,633 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 122,392 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-04-23 12:05:09
合計ジャッジ時間 69,394 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 RE -
testcase_03 AC 16 ms
5,376 KB
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 34 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 RE -
testcase_11 WA -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 53 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1,482 ms
5,376 KB
testcase_23 AC 495 ms
5,376 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 116 ms
5,376 KB
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 WA -
testcase_34 AC 68 ms
5,376 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 2 ms
5,376 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 TLE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
testcase_50 TLE -
testcase_51 RE -
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 RE -
testcase_58 RE -
testcase_59 RE -
testcase_60 RE -
testcase_61 RE -
testcase_62 RE -
testcase_63 RE -
testcase_64 RE -
testcase_65 RE -
testcase_66 RE -
testcase_67 RE -
testcase_68 RE -
testcase_69 RE -
testcase_70 RE -
testcase_71 RE -
testcase_72 RE -
testcase_73 RE -
testcase_74 RE -
testcase_75 RE -
testcase_76 RE -
testcase_77 RE -
testcase_78 AC 3 ms
5,376 KB
testcase_79 AC 125 ms
17,152 KB
testcase_80 WA -
testcase_81 RE -
testcase_82 RE -
testcase_83 RE -
testcase_84 RE -
testcase_85 RE -
testcase_86 RE -
testcase_87 RE -
testcase_88 RE -
testcase_89 RE -
testcase_90 RE -
testcase_91 RE -
testcase_92 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<random>
#include<vector>
#include <sstream>
#include <iomanip>
#include<chrono>
#include<tuple>
#include<numeric>
using namespace std;
using lli = long long int;

class rational{
public:
    rational(){x = 0, y = 1;}
    rational(lli a, lli b){x = a, y = b;}
    lli x, y;
    rational operator+(rational a){
        rational r((x*a.y + a.x*y), y*a.y);
        lli g = gcd(r.x, r.y);
        r.x /= g, r.y /= g;
        if(r.y < 0) r.x = -r.x, r.y = -r.y;
        return r;
    }
    rational operator-(rational a){
        rational r((x*a.y - a.x*y), y*a.y);
        lli g = gcd(r.x, r.y);
        r.x /= g, r.y /= g;
        if(r.y < 0) r.x = -r.x, r.y = -r.y;
        return r;
    }
    rational operator*(rational a){
        rational r(x*a.x, y*a.y);
        lli g = gcd(r.x, r.y);
        r.x /= g, r.y /= g;
        if(r.y < 0) r.x = -r.x, r.y = -r.y;
        return r;
    }
    rational operator/(rational a){
        if(a.x == 0){
            cerr << "divided by zero." << endl;
            exit(1);
        }
        rational r(x*a.y, y*a.x);
        lli g = gcd(r.x, r.y);
        r.x /= g, r.y /= g;
        if(r.y < 0) r.x = -r.x, r.y = -r.y;
        return r;
    }
};

mt19937 mt(234298343);
// uniform_int_distribution<lli> rndgen(0, 49725516559);
uniform_int_distribution<lli> rndgen(0, 1e9+7-1);

int Rank(vector<vector<rational> > M){
    // for(int i = 0; i < M.size(); i++)  {
    //     for(int j = 0; j < M.size(); j++) {
    //         cout << M[i][j].x << "/" << M[i][j].y << " ";
    //     }
    //     cout << endl;
    // }
    // cout << endl;
    // cout << endl;

    int pivot = 0, r = 0;
    rational z;
    for(int i = 0; i < M.size(); i++) {
        // cout << "i:" << i  << ", pivot:" << pivot << ", n:" << M.size() << endl;
        while(pivot < M.size()){
            for(int j = i + 1; j < M.size(); j++) {
                if(M[j][pivot].x != 0 and M[i][pivot].x == 0) swap(M[i], M[j]);
            }
            if(M[i][pivot++].x != 0) break;
        }
        if(pivot == M.size() and M[i][pivot - 1].x == 0) break;
        z = M[i][pivot - 1];

        // for(int i = 0; i < M.size(); i++)  {
        //     for(int j = 0; j < M.size(); j++) {
        //         cout << M[i][j].x << "/" << M[i][j].y << " ";
        //     }
        //     cout << endl;
        // }
        // cout << "piv:" << pivot << ", i:" << i << ", n:" << M.size() << endl;
        // cout << "z:" << z.x << "/" << z.y << endl;
        for(int j = 0; j < M.size(); j++) M[i][j] = M[i][j] / z;
        for(int j = i+1; j < M.size(); j++) {
            rational w = M[j][pivot - 1];
            // cout << "wwww:" << w.x << "/" << w.y << endl;
            for(int k = 0; k < M.size(); k++)  M[j][k] = M[j][k] - (w * M[i][k]);
        }
        // cout << endl;
        // cout << endl;
    }
    r = 1e9;
    for(int i = M.size() - 1; i >= 0 and r == 1e9; i--)  {
        for(int j = 0; j < M.size() and r == 1e9; j++) {
            if(M[i][j].x != 0) r = i + 1;
        }
    }
    // for(int i = 0; i < M.size(); i++)  {
    //     cout << "i: " << setw(2) << i << " ";
    //     for(int j = 0; j < M.size(); j++) {
    //         if(M[i][j].x != 0) cout << "1 ";
    //         else cout << "0 ";
    //     }
        // for(int j = 0; j < M.size(); j++) {
        //     cout << M[i][j].x << "/" << M[i][j].y << " ";
        // }
        // cout << endl;
    // }
    return r;
}

int main(){
    int n, m, t = 3;
    // lli mod = 49725516559;
    lli mod = 1e9+7;
    cin >> n >> m;
    vector<vector<vector<lli> > > M(t, vector<vector<lli> >(n, vector<lli>(n, 0)));
    for(int i = 0; i < m; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--, w--;
        for(int j = 0; j < t; j++) {
            lli x = rndgen(mt);
            M[j][u][v] = (M[j][u][v] + x)%mod;
            M[j][v][w] = (M[j][v][w] + x)%mod;
            M[j][w][u] = (M[j][w][u] + x)%mod;

            M[j][v][u] = (M[j][v][u] - x + mod)%mod;
            M[j][w][v] = (M[j][w][v] - x + mod)%mod;
            M[j][u][w] = (M[j][u][w] - x + mod)%mod;
        }
    }

    vector<vector<rational> > ratM(n, vector<rational>(n));
    int ans = 0;
    for(int k = 0; k < t; k++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                ratM[i][j] = rational(M[k][i][j], 1);
            }
        }
        ans = max(ans, Rank(ratM));
        // for(int i = 0; i < n; i++) {
        //     for(int j = 0; j < n; j++) {
        //         ratM[i][j] = rational(1, 1);
        //     }
        // }
        // Rank(ratM);
    }
    cout << ans/2 << endl;
}
0