QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#240212 | #4935. Exchange Bottleneck | warner1129# | WA | 1ms | 3508kb | C++20 | 1.7kb | 2023-11-05 13:42:20 | 2023-11-05 13:42:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template<class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
constexpr i64 inf = 1e18;
constexpr int mod = 1e9 + 7;
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
void solve() {
int n;
cin >> n;
vector<int> A(n);
for (int i = 1; i < n; i++) {
cin >> A[i];
}
A[0] = -1;
int cnt = ranges::count(A, 0);
debug(cnt);
if (cnt == n) {
cout << n - 1 << '\n';
} else if (cnt == n - 1 and A[1] == 1) {
cout << n - 1 << '\n';
} else if (cnt) {
int p = n - 1;
while (p >= 0 and A[p] == 0) {
p--;
}
if (p == n - 1) cout << "2\n";
else cout << 1 + (n - 1 - p) << '\n';
} else {
cout << "1\n";
}
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3472kb
input:
5 1 0 1 0
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3476kb
input:
7 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3508kb
input:
2 0
output:
2
result:
wrong answer 1st lines differ - expected: '1', found: '2'