intmain(){ cin >> n >> s + 1; int c1 = 0, c2 = 0; for (int i = 1; i <= n; i++) if (s[i] == 'R') c1++; else c2++; if (c1 > c2) puts("Yes"); elseputs("No"); return0; }
intcheck(int x){ int tot = x; for (int i = 1; i <= q; i++) { if (t[i] == s[tot]) { if (d[i] == 'L') tot--; else tot++; if (tot == 0) return1; elseif (tot == n + 1) return-1; } } return0; }
intmain(){ scanf("%d%d%s", &n, &q, s + 1); for (int i = 1; i <= q; i++) { char tmp1[3], tmp2[3]; scanf("%s%s", tmp1, tmp2); t[i] = tmp1[0]; d[i] = tmp2[0]; } int l = 1, r = n, ans1 = 0, ans2 = n + 1; while (l <= r) { int m = (l + r) >> 1; if (check(m) == 1) l = m + 1, ans1 = m; else r = m - 1; } l = 1, r = n; while (l <= r) { int m = (l + r) >> 1; if (check(m) == -1) r = m - 1, ans2 = m; else l = m + 1; } cout << n - ans1 - (n - ans2 + 1) << endl; return0; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> #include<utility> #define ms(a,b) memset(a,b,sizeof(a)) #ifdef XLor #define dbg(args...) do {cout << #args << " ->"; err(args);} while (0) #else #define dbg(...) #endif void err() {std::cout << std::endl;} template<typename T, typename...Args> void err(T a, Args...args){std::cout << a << ' '; err(args...);} using namespace std; typedef long long ll; typedef pair<int,int> PII; const int mod = 1e9 + 7; const int inf = 1 << 30; const int maxn = 100000 + 5; ll qpow(ll x, ll n) { ll r = 1; while (n > 0) { if (n & 1) r = r * x % mod; n >>= 1; x = x * x % mod; } return r; } ll inv(ll x) { return qpow(x, mod - 2); } inline void add(ll& x, ll y) { x += y; if (x >= mod) x -= mod; } int n, x, a[205]; ll dp[205][maxn]; int main() { scanf("%d%d", &n, &x); for (int i = 0; i < n; i++) scanf("%d", a + i); sort(a, a + n); dp[n][x] = 1; for (int i = n - 1; i >= 0; i--) { ll iv = inv(i + 1); for (int j = 0; j <= x; j++) { add(dp[i][j % a[i]], dp[i + 1][j] * iv % mod); add(dp[i][j], (dp[i + 1][j] - dp[i + 1][j] * iv % mod + mod) % mod); } } ll ans = 0, f = 1; for (int i = 1; i <= n; i++) f = f * i % mod; for (int i = 0; i <= x; i++) add(ans, i * dp[0][i] % mod); cout << ans * f % mod << endl; return 0; }