最后几个测试点
查看原帖
最后几个测试点
1076872
wade7916楼主2024/12/29 18:40

最后几个测试点真的太脆了,m^4秒切后面几个测试点

#include <bits/stdc++.h>
using namespace std;
int ans[1005][5];
struct St{
    int x, id;
} x[1005];
bool cmp(St A, St B){
    return A.x < B.x;
}
int main(){
    int n, m; cin >> m >> n;
    for (int i = 1; i <= n; i++) cin >> x[i].x, x[i].id = i;
    sort(x + 1, x + n + 1, cmp);
    for (int a = 1; a <= n; a++){
        for (int b = a + 1; b <= n; b++){
            if (x[b].x == x[a].x) continue;
            int t1 = 4 * x[b].x - 3 * x[a].x, t2 = x[b].x - x[a].x;
            for (int c = b + 1; c <= n; c++){
                if (x[c].x == x[b].x) continue;
                if (x[c].x <= t1) continue;
                int t3 = 2 * x[c].x;
                for (int d = c + 1; d <= n; d++){
                    if (x[d].x == x[c].x) continue;
                    if (t2 == 2 * x[d].x - t3) 
                        ans[x[a].id][1]++, ans[x[b].id][2]++, ans[x[c].id][3]++, ans[x[d].id][4]++;
                }
            }
        }
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= 4; j++) cout << ans[i][j] << ' ';
        cout << '\n';
    }
}

15-20全都不到10ms (证明

2024/12/29 18:40
加载中...