社区讨论

AC但不理解

P10040[CCPC 2023 北京市赛] 替换参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@mih869qi
此快照首次捕获于
2025/11/27 17:22
3 个月前
此快照最后确认于
2025/11/28 20:05
3 个月前
查看原帖
下面的两个代码基本没区别,code1T了,code2A了,为啥qwq
code1:
CPP
#include <bits/stdc++.h>
using namespace std;
// #define int long long    
#define usd unsigned
#define el cout << '\n'
#define lowbit(x) (x & (-x))
const int ranmod = 1e7;
#define random ((rand() * rand()) % ranmod)
#define AC return 
#define AK return 0
#define YS cout << "YES"
#define NO cout << "NO"
#define Ys cout << "Yes"
#define No cout << "No"
#define ys cout << "yes"
#define no cout << "no"
#define ls(i) ch[i][0]
#define rs(i) ch[i][1]
#define debug(num) cerr << #num << ' ' << num << '\n'
// void init();
void main_();
signed main() {
	ios :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
	int t = 1;
	// cin >> t;
	while(t--) {
		// init();
		main_();
	}
	AK;
}
const int mod = 95225987, maxn = 1e5 + 18;

int n;
string s;
bitset <maxn> unsure, sure, pos;

void main_() {
	cin >> n >> s;
    s = ' ' + s;
    for(int i = 1; i <= n; i++) {
        if(s[i] == '1') sure[i] = 1;
        if(s[i] == '?') unsure[i] = 1; 
    }
    for(int i = 1; i <= n; i++) {
        pos = sure;
        if(i * i <= n) {
            for(int j = i + 1; j <= n; j++) if(s[j] == '?' && pos[j - i] == 1) pos[j] = 1;
        } else {
            for(int j = i; j <= n; j += i) {
                pos |= (pos << i) & unsure;
            }
        }
        // for(int i = 1; i <= n; i++) cout << pos[i]; el; 
        cout << pos.count(); el;
    }
}
code2:
CPP
#include <bits/stdc++.h>
using namespace std;
// #define int long long    
#define usd unsigned
#define el cout << '\n'
#define lowbit(x) (x & (-x))
const int ranmod = 1e7;
#define random ((rand() * rand()) % ranmod)
#define AC return 
#define AK return 0
#define YS cout << "YES"
#define NO cout << "NO"
#define Ys cout << "Yes"
#define No cout << "No"
#define ys cout << "yes"
#define no cout << "no"
#define ls(i) ch[i][0]
#define rs(i) ch[i][1]
#define debug(num) cerr << #num << ' ' << num << '\n'
// void init();
void main_();
signed main() {
	ios :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
	int t = 1;
	// cin >> t;
	while(t--) {
		// init();
		main_();
	}
	AK;
}
const int mod = 95225987, maxn = 1e5 + 18;

int n, block;
string s;
bitset <maxn> unsure, sure, pos;

void main_() {
	cin >> n >> s;
    s = ' ' + s;
    block = sqrt(n);
    for(int i = 1; i <= n; i++) {
        if(s[i] == '1') sure[i] = 1;
        if(s[i] == '?') unsure[i] = 1; 
    }
    for(int i = 1; i <= n; i++) {
        pos = sure;
        if(i <= block) {
            for(int j = i + 1; j <= n; j++) if(s[j] == '?' && pos[j - i] == 1) pos[j] = 1;
        } else {
            for(int j = i; j <= n; j += i) {
                pos |= (pos << i) & unsure;
            }
        }
        // for(int i = 1; i <= n; i++) cout << pos[i]; el; 
        cout << pos.count(); el;
    }
} 

回复

2 条回复,欢迎继续交流。

正在加载回复...