Editorial for Bedao Grand Contest 07 - RESORT
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Code mẫu
#include <bits/stdc++.h> using namespace std; bool prime(int x) { if (x < 2) return 0; for (int i = 2; i * i <= x; ++i) if (x % i == 0) return 0; return 1; } int main() { freopen("RESORT.INP", "r", stdin); freopen("RESORT.OUT", "w", stdout); int n, one = 0, two = 0; cin >> n; for (int i = 1; i <= n; ++i) { int x; cin >> x; one += (x == 1); two += (x == 2); } vector <int> a(n + 10); int l = 0; if (two) a[++l] = 2, --two; if (one) a[++l] = 1, --one; for (int i = 1; i <= two; ++i) a[++l] = 2; for (int i = 1; i <= one; ++i) a[++l] = 1; int ans = 0; for (int i = 1; i <= n; ++i) ans += (prime(a[i] += a[i - 1])); cout << ans; return 0; }
Comments