#7 MLE 求助
查看原帖
#7 MLE 求助
470303
Michael_Corleone楼主2024/8/28 12:57

用 bitset 写的暴力

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 2e3 + 5, M = 5e4 + 5;
short a[M], b[M], c[M];
int n, m;
bitset<N> tag[N][N];
int main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        tag[a[i]][b[i]].set(c[i]);
    }
    int ans = 0;
    for (int i = 1; i <= m; i++)
    {
        int x = a[i], y = b[i], z = c[i];
        for (int d = z + 1; d <= n; d++)
        {
            ll s1 = tag[x][y].test(d), s2 = tag[x][z].test(d), s3 = tag[y][z].test(d);
            if (s1 && s2 && s3) ans++;
        }
    }
    cout << ans;
    return 0;
}
2024/8/28 12:57
加载中...