我真的服了
查看原帖
我真的服了
1213524
C_plus_plus_12345楼主2024/11/25 22:22

两个测试点超时( Subtask #17, 20 ),十个测试点答案错误,我也搞不懂为什么

代码

#include <iostream>
#include <string>
#include <algorithm>
 
using namespace std;

#pragma G++ optimize(2)
// 我甚至特意自己O2优化了一下
 
// 翻转二进制字符串,直接修改输入字符串
void flip(string& s)
{
    reverse(s.begin(), s.end());
}
 
// 取反二进制字符串,直接修改输入字符串
void bitNot(string& s)
{
    for (char& c : s)
    {
        c = c == '0' ? '1' : '0';
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr); // nullptr其实就是0的一种体现。
 
    int n, s;
    string t, y;
 
    // 输入二进制字符串的长度 n 和操作次数 s
    cin >> n >> s;
    cin.ignore(); // 忽略换行符
 
    // 输入二进制字符串 t
    cin >> t;
 
    // 输入操作字符串 y
    cin >> y;
    
    if(y.length() % 2 == 0)
    {
		cout << t;
		return 0;
	}
 
    // 对字符串 t 进行操作
    for (char op : y)
    {
        if (op == '1')
        {
            flip(t);
        }
        else if (op == '2')
        {
            bitNot(t);
        }
    }
 
    // 输出结果
    cout << t << endl;
 
    return 0;
}
2024/11/25 22:22
加载中...