比赛环境配置及机器测试

$coderunner$配置:注意打开:Run In Terminal设置,不然无法手动输入

"cpp": "cd $dir && g++ $fileName  -Wall -Wextra 
 -fsanitize=undefined -DLOCAL -D_GLIBCXX_DEBUG 
 -std=c++17 -g -O2 -o $fileNameWithoutExt && $dir/$fileNameWithoutExt"

编译命令可加参数:

-fdiagnostics-color=always //启用彩色诊断信息
-pg// 启用性能分析
    
-Wno-sign-compare//禁用有符号和无符号比较的警告
-Wl,--stack=1024102422//windows下调整栈大小976MB

其他配置:Settings

  • zoom->Mouse Wheel Zoom
  • Files: Auto Save->$AfterDelay$
  • Auto Save Delay->500

初始化模板:

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define deb(x) (void)(cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl)
#else
#define deb(x)
#endif
#define ll long long
// #define int long long
#define baoliu(x, y) cout << fixed << setprecision(y) << x
#define endl "\n"
const int mod = 998244353;
const double eps = 1e-8;
const double PI = acos(-1.0);
void solve() {
    
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef LOCAL
    double starttime = clock();
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    while (t--) solve();
#ifdef LOCAL
    double endtime = clock();
    cerr << "Time Used: " << (double)(endtime - starttime) / CLOCKS_PER_SEC * 1000 << " ms" << endl;
#endif
    return 0;
}

测试机器:

  1. 确认编译错误不罚时

  2. 测试速度bitset

  3. 测试栈大小

  4. 测试静态内存容量是多大

1.GNU C++ 版本及64位测试:

#include <bits/stdc++.h>
using namespace std;
using i128 = __int128;
int main()
{
    // GNU C++11: Array
    array<int, 3> C = {1, 2, 3};
    for (int i : C)
    {
        cout << i << " ";
    }
    //test 64bit
    i128 tmp = 0;
    tmp++;
    cout << endl;
    // GNU C++14: Recursive lambda with auto
    auto dfs = [&](auto self, int x) -> void
    {
        if (x > 10)
            return;
        cout << "DFS at x = " << x << endl;
        self(self, x + 1);
    };
    dfs(dfs, 1);
    // GNU C++17: Template argument deduction for vector
    vector in(2, vector<int>(2, 1));
    for (auto x : in)
    {
        for (auto y : x)
        {
            cout << y << " ";
        }
        cout << endl;
    }

    // GNU C++17: Structured bindings
    map<int, int> dic = {{1, 2}, {3, 4}};
    for (auto [u, v] : dic)
    {
        cout << "{" << u << ", " << v << "} ";
    }
    cout << endl;
    // GNU C++20: contains method for map
    if (dic.contains(1))
    {
        cout << "contains" << endl;
    }
    else
    {
        cout << "not contain" << endl;
    }
    return 0;
}

2.速度测试:8e9级别

Atocder:不开优化874 ms,开优化875 ms.

n开到5000Atocder:不开优化874 ms,开优化875 ms.

Codeforcs:不开优化ms,开优化 ms

Qoj:不开优化 4347ms,开优化1734ms

注意一个事:如果n开到5000.。Atocder:不开优化8348 ms,开优化1696ms.

// #pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
signed main() {
    int n = 4E3;
    bitset<30> ans;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j += 2) {
            for (int k = 1; k <= n; k += 4) {
                ans |= i | j | k;
            }
        }
    }
    cout << ans.to_ullong() << "\n";
}

3.栈大小测试

#include <bits/stdc++.h>
using namespace std;
int cur = 1;
// 需要关闭O2测试
void func() {
    cout << cur << "MB" << endl;
    char arr[1024 * 1024];  // 1MB
    // 使用数组以防止优化
    // if (cur > 1024 )
    //     return;
    int sum = 0;
    cur++;
    func();
}
int main() {
    func();
    cout << "Yes" << endl;
    cout << cur << "MB" << endl;
    return 0;
}

4.静态内存容量:MLE->RE

1024Mb->$2.6 \times 10^8$个int(268435456)

#include <iostream>
using namespace std;
const int N=268435456;//1024MB
//static int a[N]; // 尝试设置为更大的值
int a[N+10]; // 尝试设置为更大的值

int main() {
   for(int i=1;i<=N;i++)a[i]=i&(i-1);
    cout << "Yes" << endl;
    return 0;
}