用 AI 的力量提高切题体验

写这个东西的动机是去 [数据删除] 集训的时候发现师者 [数据删除] 用这种方式写题,我发现这样集成的环境可太爽了啊。

还有一些原因就是测试大样例的时候总是有些不方便,即使是 vscode 的 cph 插件也会因为样例太大在终端造成严重的卡顿。

以及现在在 CF 交题如果是复制粘贴代码交总要过一堆 cloudflare,但是直接提交文件似乎就没这个限制。而且在题目右侧点进去的提交文件是要比点到 submit 里面复制粘贴要快一些的。(虽然说我也没打过 CF)

还有,使用这些工具时除了复制粘贴样例和提交代码环节,全程都在键盘上完成。

要使用这些,你只需要 vscode 和 g++ 编译器。

接下来用一个工作流的例子展示下这东西怎么用吧。

POV

假设你现在正在做 CF2043E

您看一眼就秒了这题,现在打开 vscode 准备切。

打开 vscode 后,你会进入到一个这样的工作环境中:

image

接下来,你使用 Ctrl + ` 快捷键聚焦到终端位置,键入 .\new 并回车:

image

你输入题目名称 CF2043E.cpp 并按下回车:

image

工具自动在 .\working 文件夹中创建了 CF2043E.cpp 并在 vscode 中打开了该文件,接下来是您的切题时间。

您用 1ms 就写完了这题。接下来,如果你有 cph 插件,你可以使用 cph 插件测试小样例。当然内置的样例测试功能也可以测试小样例,只不过它是为了大样例准备的。

您毫无悬念的通过了所有小样例,接下来直接去题目旁提交文件。选择文件按钮会记住你上次提交的文件路径,因此点击选择后直接显示的就是 .\working 文件夹,你选中文件 CF2043E.cpp,点击提交

依然毫无悬念的通过了。接下来你去洛谷的讨论区逛了逛,发现有位仁兄提供了一个 hack,你觉得有点意思就下载下来发现这个样例太大了。

于是你把它复制下来粘贴到工作区里的 a.in 文件夹,将答案放在 std.out 文件夹:

image

接下来切换到终端,你输入 .\ck 并按下回车:

image

程序将会自动找到 .\working 文件夹下的 .cpp 文件,编译出一个 running.exe 并运行 a.in 中的样例,将结果存放至 a.out 中。同时会给出程序的运行时间。

你在终端中输入 .\j 并按下回车:

image

程序调用 fc 命令比较文件,您依然通过了这份 hack 数据。

你心满意足的准备去写下一题,在终端中输入 .\bash 并回车:

image

工具清空了 .\working 文件夹中的所有 .in .out 文件的内容,删除了所有 .exe 文件,将所有的 .cpp 文件移动到 .\lib 文件夹中储存。

工作区恢复成了初始状态,接下来再次输入 .\new 即可开始下一题。

说些闲话

这些东西都是用原生 C++14 写的,当然造轮子的部分都是 deepseek 完成的,主函数部分是我写的。

如果你也想用这种方式写题,我更推荐你去找 AI DIY 一份。

你可能会问为什么不把 fc 部分和编译运行的 .\ck 放在一起,原因是 windows 的 fc 太严格了,不会自动过滤空格和回车什么的,于是这个 fc 只能仅供参考的独立出来了。

虽然当时,AI 写的东西也挺多 bug,我在代码中用的都是相对路径,于是就会出现相对路径乱跑导致的各种奇异错误,好在现在代码里应该是没什么问题了。

下面把代码放出来了,这些代码应该只有 windows 环境能用,但是由于用的相对路径,你只需要把这些 .cpp 编译出的 .exe 随便放到同一个文件夹下应该就能用了。

当然记得建好 .\working.\lib,如果想改名找源码修改就行了。

代码都是很标准且现代化的 2 空格缩进!

new.cpp
#include <iostream>
#include <fstream>
#include <string>

bool CreateFile(const std::string& filePath) {
  std::ofstream file(filePath);
  if (file.is_open()) {
    file.close();
    return true;
  }
  return false;
}

int main() {
  std::string path = ".\\working\\";

  std::string Name;

  std::cout<<"-> Enter file name"<<std::endl;

  std::cin>>Name;
    
  path.append(Name);

  if (CreateFile(path)) {
    std::cout << "-> File " << Name << " has created" << std::endl;

    std::string command="code ";
    command.append(path);
    command.append("\"");

    system(command.c_str());
  } 
  else {
    std::cerr << "-> Failed to create" << std::endl;
  }

  return 0;
}
ck.cpp
#include <windows.h>
#include <dirent.h>
#include <bits/stdc++.h>

const std::string relpath=".\\working\\";

std::string GetSingleCppFile(const std::string& folderPath) {
  DIR* dir;
  struct dirent* ent;
  std::vector<std::string> cppFiles;

  if ((dir = opendir(folderPath.c_str())) != nullptr) {
    while ((ent = readdir(dir)) != nullptr) {
      std::string name = ent->d_name;
      if (name.size() > 4 && 
        name.compare(name.size() - 4, 4, ".cpp") == 0) {
        cppFiles.push_back(name);
      }
    }
    closedir(dir);

    if (cppFiles.empty()) {
      std::cerr<<"-> No *.cpp files detected"<<'\n';
    } 
    else if (cppFiles.size() > 1) {
      std::cerr<<"-> Multiple *.cpp files detected"<<'\n';
    }
    else{
    }
    return cppFiles[0];
  } 
  else {
    std::cerr<<"-> Cannot open directory"<<'\n';
  }
}

int main(){

  std::string pth=GetSingleCppFile(relpath);

  std::string path=relpath;

  std::string path_ain=relpath;
  std::string path_aout=relpath;

  path_ain.append("a.in");
  path_aout.append("a.out");
  path.append(pth);

  std::string cmp="g++ ";
  cmp.append(path);
  cmp.append(" -o ");
  cmp.append(relpath);
  cmp.append("running.exe -std=c++14");

  std::cout<<"->   "<<cmp<<std::endl;

  system(cmp.c_str());

  std::string runc="\"";

  runc.append(relpath);
  runc.append("running.exe");
  runc.append(" < ");
  runc.append(path_ain);
  runc.append(" > ");
  runc.append(path_aout);
  runc.append("\"");

  std::cout<<"->   "<<runc<<std::endl;
  
  double _beg=clock();
  system(runc.c_str());
  double _end=clock();

  std::cout<<"program used "<<_end-_beg<<" ms"<<std::endl;

  return 0;
}
j.cpp
#include<bits/stdc++.h>
#include<windows.h>

const std::string relpath=".\\working\\";

int main(){

  std::string a="";
  a.append(relpath);
  a.append("a.out");

  std::string _std="";
  _std.append(relpath);
  _std.append("std.out");

  std::string runc="fc ";
  runc.append(a);
  runc.append(" ");
  runc.append(_std);

  system(runc.c_str());

  return 0;
}
bash.cpp
#include <iostream>
#include <string>
#include <dirent.h>
#include <fstream>
#include <cstdio>

void delete_exe_files(const std::string& dir) {
  DIR* dp = opendir(dir.c_str());
  struct dirent* ep;
  while ((ep = readdir(dp))) {
    std::string name = ep->d_name;
    if (name.size() > 4 && name.substr(name.size() - 4) == ".exe") {
      std::remove((dir + "/" + name).c_str());
    }
  }
  closedir(dp);
}

void move_cpp_files(const std::string& src_dir, const std::string& dst_dir) {
  DIR* dp = opendir(src_dir.c_str());
  struct dirent* ep;
  while ((ep = readdir(dp))) {
    std::string name = ep->d_name;
    if (name.size() > 4 && name.substr(name.size() - 4) == ".cpp") {
      std::rename(
        (src_dir + "/" + name).c_str(),
        (dst_dir + "/" + name).c_str()
      );
    }
  }
  closedir(dp);
}

void clear_in_files(const std::string& dir) {
  DIR* dp = opendir(dir.c_str());
  struct dirent* ep;
  while ((ep = readdir(dp))) {
    std::string name = ep->d_name;
    if (name.size() > 3 && name.substr(name.size() - 3) == ".in") {
      std::ofstream((dir + "/" + name), std::ios::trunc).close();
    }
  }
  closedir(dp);
}
void clear_out_files(const std::string& dir) {
  DIR* dp = opendir(dir.c_str());
  struct dirent* ep;
  while ((ep = readdir(dp))) {
    std::string name = ep->d_name;
    if (name.size() > 4 && name.substr(name.size() - 4) == ".out") {
      std::ofstream((dir + "/" + name), std::ios::trunc).close();
    }
  }
  closedir(dp);
}

int main() {
  std::string src_dir = ".\\working\\";
  std::string dst_dir = ".\\lib";

  delete_exe_files(src_dir);
  move_cpp_files(src_dir, dst_dir);
  clear_in_files(src_dir);
  clear_out_files(src_dir);

  std::cout << "done";
  return 0;
}
CF2043E.cpp
#define psb push_back
#define mkp make_pair
#define ls p<<1
#define rs (p<<1)+1
#define rep(i,a,b) for( int i=(a); i<=(b); ++i)
#define per(i,a,b) for( int i=(a); i>=(b); --i)
#define rd read()
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
  ll x=0,f=1;
  char c=getchar();
  while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+(c^48);c=getchar();}
  return x*f;
}
const int N=2000;
int n,m;
int ori[N][N];
int bsh[N][N];
bitset<N> prm[40][N];
bitset<N> msk[40][N];
bitset<N> ok[40][N];
bitset<N> col[40],lin[40];
void init(){
  for(int k=0;k<=31;k++){
    col[k].reset();lin[k].reset();
    for(int i=1;i<=n;i++){
      for(int j=1;j<=m;j++){
        prm[k][i][j]=msk[k][i][j]=ok[k][i][j]=0;
      }
    }
  }
  return ;
}
void solve(){
  cin>>n>>m;
  for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
    cin>>ori[i][j];
    int x=ori[i][j];
    for(int k=0;k<=31;k++){
      prm[k][i][j]=(x>>k)&1;
    }
  }
  for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){
    cin>>bsh[i][j];
    int x=bsh[i][j];
    for(int k=0;k<=31;k++){
      msk[k][i][j]=(x>>k)&1;
    }
  }
  for(int k=0;k<=31;k++){
    bool opt=1;
    for(int ctt=1;ctt<=max(n,m);ctt++){
      if(ctt>1&&!opt)break;
      for(int i=1;i<=n;i++){
        if(lin[k][i])continue;
        bool all0=1;
        for(int j=1;j<=m;j++){
          if(!ok[k][i][j]&&msk[k][i][j]){all0=0;break;}
        }
        if(!all0)continue;
        lin[k][i]=1;
        for(int j=1;j<=m;j++)ok[k][i][j]=1;
        opt=1;
      }
      if(ctt>1&&!opt)break;
      opt=0;
      for(int j=1;j<=m;j++){
        if(col[k][j])continue;
        bool all1=1;
        for(int i=1;i<=n;i++){
          if(!ok[k][i][j]&&msk[k][i][j]==0){all1=0;break;}
        }
        if(!all1)continue;
        col[k][j]=1;
        for(int i=1;i<=n;i++)ok[k][i][j]=1;
        opt=1;
      } 
    }
    
  }
  for(int k=0;k<=31;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=m;j++){
        if(ok[k][i][j]||prm[k][i][j]==msk[k][i][j])continue;
        else {
          cout<<"No"<<'\n';
          goto lab;
        }
      }
    }
  }
  cout<<"Yes"<<'\n';
  lab:
    return ;
}
int main(){
  
  int T;cin>>T;
  while(T--){
    init();solve();
  }
  
  return 0;
}
posted @ 2025-08-11 22:43  hm2ns  阅读(44)  评论(2)    收藏  举报