code_file1
stringlengths
80
4k
code_file2
stringlengths
91
4k
similar_or_different
int64
0
1
#include <algorithm> #include <bitset> #include <tuple> #include <cstdint> #include <cstdio> #include <cctype> #include <assert.h> #include <stdlib.h> #include <stdio.h> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <limits> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; using ld = long double; #define endl "\n" //#define int long long #define ALL(x) begin(x),end(x) #define RALL(a) (a).rbegin(), (a).rend() #define _CRT_SECURE_NO_WARNINGS #define rep(i, n) for (int i = 0; i < n; i++) const int MOD = 1e9 + 7; const ll INF = 1LL << 60; const int inf = 1 << 25; constexpr long double pi = 3.141592653589793238462643383279; int dx[] = { 1,0,-1,0 }; int dy[] = { 0,1,0,-1 }; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } ll fact(ll i) { if (i == 0) return 1; return ((fact(i - 1)) * i) % MOD; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll keta(ll n) { if (n == 0) return 1; ll count = 0; while (n != 0) { n /= 10; count++; } return count; } ll ketasum(ll n) { ll sum = 0; while (n != 0) { sum += n % 10; n /= 10; } return sum; } ll mch(ll n) { if (n == 1) return 1; else return n * mch(n - 1); } ll modpow(ll a, ll n, ll mod) { ll hi = 1; while (n > 0) { if (n & 1) hi = hi * a % mod; a = a * a % mod; n >>= 1; } return hi; } bool is_prime(const unsigned n) { switch (n) { case 0: // fall-through case 1: return false; case 2: // fall-through case 3: return true; } // n > 3 が保証された if (n % 2 == 0 || n % 3 == 0) return false; for (unsigned i = 5; i * i <= n; i += 6) { if (n % i == 0) return false; // (6の倍数)-1 if (n % (i + 2) == 0) return false; // (6の倍数)+1 } return true; } /*signed*/int main(void) { int n, m; cin >> n >> m; vector<pair<int, int>> p(m); rep(i, m) { int s, c; cin >> s >> c; s--; p[i] = make_pair(s, c); } rep(i, 1000) { string s = to_string(i); if (s.size() == n) { bool ans = true; rep(j, m) { if ((s[p[j].first] - '0') != p[j].second)ans = false; } if (ans) { cout << i << endl; return 0; } } } cout << -1 << endl; return 0; }
#include<iostream> #include<vector> using namespace std; int main() { int n, m, s, c; int ans = 0; vector<int> a(5, -1); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> s >> c; if (s == 1 && c == 0 && n != 1) ans = -1; if (a[s] == -1 || a[s] == c) a[s] = c; else ans = -1; } if (ans == -1) cout << ans << endl; else { if (a[1] == -1 && n != 1) a[1] = 1; for(int i = 1; i <= n; i++) { if (a[i] == -1) a[i] = 0; cout << a[i]; } cout << endl; } }
1
#include <bits/stdc++.h> using namespace std; #define vt vector #define sz(x) int((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fi first #define se second using ll = long long; using pii = pair<int, int>; void solve() { string s, t; cin >> t >> s; cout << s + t; } int main() { ios::sync_with_stdio(0), cin.tie(0); int tcs = 1; for (int tc = 1; tc <= tcs; tc++) { // cout << "Case " << tc << ": "; solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; using P = pair<ll, ll>; using V = vector<ll>; #define rep(i, n) for(ll i=0;i<(ll)(n);i++) #define rep1(i, n) for(ll i=1;i<=(ll)(n);i++) #define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++) #define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define MOD 1000000007 #define INF 1000000000 #define LLINF 1e18 template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T & a, const T & b) { if (b < a) { a = b; return 1; } return 0; } void solve_abc_a() { ll n, m; ll x, y; ll a, b, d; ll c; //char c; ll h, w; ll k; string s, t; //ll s, t; ll l_ans = 0; string s_ans = "NG"; V val(3, 0); cin >> val[0] >> val[1] >> val[2] >> k; sort(ALL(val)); val[2] = val[2] * pow(2, k); l_ans = val[0] + val[1] + val[2]; cout << l_ans << "\n"; return; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed; cout << setprecision(7); solve_abc_a(); return 0; }
0
// 2016-12-03 #include <iostream> #include <cmath> using namespace std; int main() { int m, min, max, n; int p[200]; while (cin >> m >> min >> max, m) { for (int i = 0; i < m; i++) { cin >> p[i]; } n = min - 1; for (int i = min; i < max; i++) { if (p[i] - p[i + 1] >= p[n] - p[n + 1]) { n = i; } } cout << n + 1 << endl; } return 0; }
#include <iostream> #include <stdio.h> #include <string.h> #include <string> #include <functional> #include <algorithm> #include <string> #include <vector> #include <algorithm> #include <time.h> #include <stdlib.h> #include <math.h> using namespace std; int main (void) { long m,min,max,p[10000],g[10000],kkk,rrr; for (long o = 0; o < 10000; o++) { cin >> m >> min >> max; if (m == 0 && min == 0) { if (max == 0) { break; } } kkk = 0; for (long i = 1; i < m + 1; i++) { cin >> p[i]; } for (long j = min; j < max + 1; j++) { g[j] = p[j] - p[j + 1]; if (kkk <= g[j]) { kkk = 0; kkk = g[j]; rrr = 0; rrr = j; } } cout << rrr << endl; } }
1
#include "bits/stdc++.h" using namespace std; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; #define rep(i, begin, n) for (int i = begin; i < n; i++) #define repe(i, begin, n) for (int i = begin; i <= n; i++) #define repr(i, begin, n) for (int i = begin; i > begin - n; i--) #define repre(i, begin, end) for (int i = begin; i >= end; i--) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const int inf = INT_MAX; const int MOD = 1000000007; const long long INF = LLONG_MAX; // ------------------------------------------------------- ll x; int main() { cin >> x; ll q = x / 11; ll r = x % 11; if (r == 0) { cout << q * 2; return 0; } if (1 <= r && r <= 6) { cout << q * 2 + 1; return 0; } cout << q * 2 + 2; }
#include<iostream> #include<vector> #include<algorithm> #include<queue> using namespace std; long long int gcd(long long int a,long long int b){ if(a%b==0){ return b; } else{ return gcd(b,a%b); } } long long int fac(long long int n){ if(n==0){ return 1; } else{ return n*(fac(n-1))%1000000007; } } int main(){ long long int n,k,ans=0; cin>>n; ans+=2*((n-1)/11); if(n%11<7&&n%11>0){ ans++; } else{ ans++; ans++; } cout<<ans<<endl; return 0; }
1
#include<iostream> #include<vector> #include<string> #include<sstream> int main() { std::vector<std::string>result; for (std::string s; std::getline(std::cin, s);) { int delta = 0; std::stringstream ss; ss << s; while (!ss.eof()) { std::string temp; ss >> temp; if (temp.length() == 3 && temp[0] != '.' && temp[1] != '.' && temp[2] != '.') { int d1 = temp[0] - 't'; int d2 = temp[1] - 'h'; int d3 = temp[2] - 'e'; for (auto i : { &d1,&d2,&d3 }) { if (*i < 0) { *i += 26; } } if (d1 == d2 && d2 == d3) { delta = temp[0] - 't'; break; } } else if (temp.length() == 4 && temp[0] != '.' && temp[1] != '.' && temp[2] != '.' && temp[3] != '.') { int d1 = temp[0] - 't'; int d2 = temp[1] - 'h'; int d3 = temp[2] - 'i'; int d4 = temp[3] - 's'; for (auto i : { &d1,&d2,&d3,&d4 }) { if (*i < 0) { *i += 26; } } if (d1 == d2 && d2 == d3 && d3 == d4) { delta = temp[0] - 't'; break; } d1 = temp[0] - 't'; d2 = temp[1] - 'h'; d3 = temp[2] - 'a'; d4 = temp[3] - 't'; for (auto i : { &d1,&d2,&d3,&d4 }) { if (*i < 0) { *i += 26; } } if (d1 == d2 && d2 == d3 && d3 == d4) { delta = temp[0] - 't'; break; } } } result.push_back(std::string(s.length(), 'a')); for (int i = 0; i < s.length(); i++) { result.back()[i] = 'a' <= s[i] && s[i] <= 'z' ? (s[i] - delta - 'a') % 26 + 'a' : s[i]; } } for (auto i : result) { std::cout << i << std::endl; } return 0; }
#include <iostream> #include <stdio.h> #include <string.h> #define MAX 100 //#define NIL -1 struct Node { int key; Node *parent, *left, *right; }; Node *root, *NIL; int n; void insert(int val) { Node *y = NIL; Node *x = root; Node *z = new Node(); z->key = val; z->left = NIL; z->right = NIL; while (x != NIL) { y = x; if (z->key > x->key) { x = x->right; } else { x = x->left; } } z->parent = y; if ( y == NIL ) { root = z; } else if ( y->key > z->key ) { y->left = z; } else { y->right = z; } // delete z; } Node * find(Node *x, int val) { while ( x != NIL) { if (x->key == val) break; if (x->key > val) { x = x->left; } else { x = x->right; } } return x; } Node * getSuccessor(Node *u) { while (u->left != NIL) { u = u->left; } return u; } void delete_node(Node *u) { Node *y; Node *x; if (u->left != NIL && u->right != NIL) { y = getSuccessor(u->right); } else { y = u; } // search child if (y->left != NIL) { x = y->left; } else { x = y->right; } // set the parent to the child if it exists if (x != NIL) { x->parent = y->parent; } if ( y->parent == NIL ) { root = x; } else if (y == y->parent->left) { y->parent->left = x; } else { y->parent->right = x; } if ( u != y ) { u->key = y->key; } delete y; } void preorder(Node *u) { if (u == NIL) return; printf(" %d", u->key); preorder(u->left); preorder(u->right); } void inorder(Node *u) { if (u == NIL) return; inorder(u->left); printf(" %d", u->key); inorder(u->right); } void print() { inorder(root); printf("\n"); preorder(root); printf("\n"); } int main() { int val; char moji[10]; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s", moji); if (moji[0] == 'i') { scanf("%d", &val); insert(val); } else if (moji[0] == 'f') { scanf("%d", &val); Node *t = find(root, val); if ( t != NIL ) printf("yes\n"); else printf("no\n"); } else if (moji[0] == 'd') { scanf("%d", &val); Node *t = find(root, val); delete_node(t); } else { print(); } } return 0; }
0
#include <cstdio> #include <cstring> int main() { char str[110]; scanf("%s", str); str[strlen(str) - 8] = 0; puts(str); return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long int #define rep(i,n) for( int i = 0; i < n; i++ ) #define rrep(i,n) for( int i = n; i >= 0; i-- ) #define REP(i,s,t) for( int i = s; i <= t; i++ ) #define RREP(i,s,t) for( int i = s; i >= t; i-- ) #define dump(x) cerr << #x << " = " << (x) << endl; #define INF 2000000000 #define mod 1000000007 #define INF2 1000000000000000000 int main(void) { cin.tie(0); ios::sync_with_stdio(false); int R; cin >> R; if( R < 1200) cout << "ABC" << endl; else if (R < 2800) cout << "ARC" << endl; else cout << "AGC" << endl; return 0; }
0
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> // Acknowledgement: Special thanks to kyomukyomupurin, who developed this // template. template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '(' << p.first << ", " << p.second << ')'; } template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { int n = 0; for (auto e : vec) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { int n = 0; for (auto e : st) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { int n = 0; for (auto e : mp) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& e : vec) is >> e; return is; } #ifdef LOCAL #define debug(...) \ std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head&& head, Tail&&... tail) { std::cerr << head; if (sizeof...(Tail) != 0) std::cerr << ", "; debug_out(std::forward<Tail>(tail)...); } using namespace std; using int64 = long long; int main() { string X; cin >> X; int X_size = X.size(); int delete_num = 0; int S_left_num = 0; for (int i = 0; i < X_size; i++) { if (X[i] == 'S') S_left_num++; else { if (S_left_num) { S_left_num--; delete_num += 2; } } } cout << X_size - delete_num << endl; return 0; }
#include<iostream> #include<cstdio> #include<string> using namespace std; int main() { string a; cin>>a; int tmp=a.find("ST"); while(a.length()>0&&tmp>=0) { a.erase(tmp,2); int x=max(tmp-1,0); tmp=a.find("ST",x); if(tmp==string::npos&&(a[tmp]!='S'||a[tmp+1]!='T')) tmp=-1; } cout<<a.length()<<endl; return 0; }
1
#include<bits/stdc++.h> int main(){ using namespace std; unsigned long N; cin >> N; unsigned long ans{~0UL}; for(unsigned long i{0}, pa{~0UL}, a; i < N; ++i){ cin >> a; if(pa + 1 < a)return 0 & puts("-1"); if(pa + 1 == a)++ans; else ans += a; pa = a; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // boost #include <boost/multiprecision/cpp_int.hpp> using boost::multiprecision::cpp_int; using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using vb = vector<bool>; using vs = vector<string>; using vld = vector<ld>; using vvld = vector<vld>; typedef pair<ll, ll> P; #define bit(n) (1LL << (n)) //#define int long long #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < n; i++) #define REP(i, n) for (ll i = 1; i < n; i++) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++) template <class T> inline void chmax(T& a, T b) { a = std::max(a, b); } template <class T> inline void chmin(T& a, T b) { a = std::min(a, b); } #define mod (ll)(1e9 + 7) // #define mod (998244353ll) const long long INF = 1LL << 60; signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; if (a[0] != 0) { cout << -1 << endl; return 0; } REP(i, n) { if (a[i] >= a[i - 1] + 2) { cout << -1 << endl; return 0; } } ll ans = a[n - 1]; for (int i = n - 2; i > 0; i--) { if (a[i] != a[i + 1] - 1) { ans += a[i]; } } cout << ans << endl; return 0; }
1
#include <iostream> #include <algorithm> #include <fstream> using namespace std; int N = 0, M = 0; int points[1001]; int scores[1002001]; bool check(int a, int c){ if(a >= (N + 2) * (N + 1) / 2 - 1){ return true; } return (scores[a] <= c && scores[a + 1] > c); } int search2(int a, int b, int c){ int pib = a + b - b / 2; if(check(pib, c)){ return pib; }else if(scores[pib] < c){ return search2(pib, b / 2, c); }else{ return search2(a, b / 2, c); } } int main(){ for(;;){ for(int i = 0; i < 1001; i++){ points[i] = 0; } for(int i = 0; i < 1002001; i++){ scores[i] = 0; } if(cin >> N){ if(N == 0){ break; } cin >> M; for(int i = 1; i <= N; i++){ cin >> points[i]; } for(int i = 0; i <= N; i++){ for(int j = i; j <= N; j++){ scores[(2 * N - i + 1) * i / 2 + j] = points[i] + points[j]; } } int mxsco = 0; sort(scores, scores + ((N + 2) * (N + 1)) / 2); for(int i = 0; i < (N + 2) * (N + 1) / 2; i++){ if(scores[i] > M){ break; } int nosco = scores[i] + scores[search2(0, (N + 2) * (N + 1) / 2, M - scores[i])]; if(nosco >= mxsco && nosco <= M){ mxsco = nosco; } } cout << mxsco << endl; }else{ break; } } return 0; }
#include <iostream> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <algorithm> #include <cstdio> #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define FORR(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) #define INF 999999999 using namespace std; typedef pair<int, int> P; int dy[]={0, 0, 1, -1}; int dx[]={1, -1, 0, 0}; int n; llong m; int main(){ while(1){ scanf("%d%lld", &n, &m); if(n==0 && m==0) return 0; n++; vector<llong> p(n); p[0]=0; FOR(i, 1, n) scanf("%lld", &p[i]); VSORT(p); int size=0; vector<llong> v; REP(i, n){ REP(j, n){ v.push_back(p[i]+p[j]); } } VSORT(v); llong ans=0; REP(i, v.size()){ int rem=m-v[i]; if(rem < 0) continue; int l=0, r=v.size(); while(l<r){ int mid=(l+r)/2; if(rem>v[mid]){ l=mid+1; } else if(rem<v[mid]){ r=mid; } else { break; } } ans = max(ans, v[i]+v[r-1]); } printf("%d\n",ans); } }
1
#include<iostream> #include<vector> using namespace std; long long cnt=0; void insertionSort(int numbers[],int n,int g) { for(int i=g;i<n;i++) { int v=numbers[i]; int j=i-g; while(j>=0&&numbers[j]>v) { numbers[j+g]=numbers[j]; j=j-g; cnt++; } numbers[j+g]=v; } } void shellSort(int numbers[],int n) { // int m=2; //生成数列G int G[2]={4,1} vector<int> G; for(int i=1;i<=n;) { G.push_back(i); i=i*3+1; } for(int i=G.size()-1;i>=0;i--) { insertionSort(numbers,n,G[i]); } cout<<G.size()<<endl; for(int i=G.size()-1;i>0;i--) { cout<<G[i]<<" "; } cout<<G[0]; cout<<endl; } int main() { int n; cin>>n; int numbers[1000000]; for(int i=0;i<n;i++) { cin>>numbers[i]; } shellSort(numbers,n); cout<<cnt<<endl; for(int i=0;i<n;i++) { cout<<numbers[i]<<endl; } }
#include <iostream> #include <vector> #include <algorithm> #include <cstdio> #include <math.h> using namespace std; typedef long long ll; int main() { int v[100]; int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> v[i]; } for (int i = n-1; i >= 0; --i) { if (i != n-1) cout << " "; cout << v[i]; } cout << endl; }
0
#include <algorithm> #include <iostream> using namespace std; const int MAX_V = 100; const long long INF = (1LL << 32); long D[MAX_V][MAX_V]; int V; void wf() { for (int k = 0; k < V; k++) { for (int i = 0; i < V; i++) { if (D[i][k] == INF) continue; for (int j = 0; j < V; j++) { if (D[k][j] == INF) continue; D[i][j] = min(D[i][j], D[i][k] + D[k][j]); } } } } int main() { int e; cin >> V >> e; for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { D[i][j] = ((i == j) ? 0 : INF); } } for (int i = 0; i < e; i++) { int s, t; cin >> s >> t; long d; cin >> d; D[s][t] = d; } wf(); bool negative = false; for (int i = 0; i < V; i++) { if (D[i][i] < 0) negative = true; } if (negative) { cout << "NEGATIVE CYCLE" << endl; return 0; } for (int i = 0; i < V; i++) { for (int j = 0; j < V; j++) { if (j) cout << ' '; if (D[i][j] == INF) cout << "INF"; else cout << D[i][j]; } cout << endl; } return 0; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; const double pi = acos(-1); struct Edge { ll to, cost; Edge(ll to, ll cost):to(to),cost(cost) {} }; struct Data { ll v, x; // いまいる頂点v, 進んだ距離x Data(ll v, ll x):v(v),x(x) {} bool operator<(const Data& hoge) const { return x > hoge.x; } }; int main() { ll n; cin >> n; vector<vector<Edge>> G(n); rep(i, n-1) { ll a, b, c; cin >> a >> b >> c; a--; b--; G[a].emplace_back(b, c); G[b].emplace_back(a, c); } ll q, sv; cin >> q >> sv; sv--; vl dp(n, INF); priority_queue<Data> Q; auto push = [&](ll v, ll x) { if(dp[v] <= x) { return; } dp[v] = x; Q.emplace(v, x); }; // ダイクストラ法。計算量はO((V+E)*log(V)) push(sv, 0); while(!Q.empty()) { Data hoge = Q.top(); Q.pop(); ll v = hoge.v, x = hoge.x; if(dp[v] != x) { continue; } for(Edge e : G[v]) { push(e.to, x + e.cost); } } rep(i, q) { ll x, y; cin >> x >> y; x--; y--; out(dp[x] + dp[y]); } re0; }
0
#include<bits/stdc++.h> using namespace std; int n,a=-1,b=-1,mp[1005][1005]; int mex(vector<int> a){ sort(a.begin(),a.end()); int now=1; for(auto x:a){ if(x>now)return now; else if(x==now)++now; } return now; } void p21(int x,int y){ vector<int>t; if(mp[x-1][y])t.push_back(mp[x-1][y]); if(mp[x][y-1])t.push_back(mp[x][y-1]); if(mp[x][y+1])t.push_back(mp[x][y+1]); if(mp[x+1][y-1])t.push_back(mp[x+1][y-1]); if(mp[x+1][y+1])t.push_back(mp[x+1][y+1]); if(mp[x+2][y])t.push_back(mp[x+2][y]); mp[x][y]=mp[x+1][y]=mex(t); } void p12(int x,int y){ vector<int>t; if(mp[x][y-1])t.push_back(mp[x][y-1]); if(mp[x-1][y])t.push_back(mp[x-1][y]); if(mp[x+1][y])t.push_back(mp[x+1][y]); if(mp[x-1][y+1])t.push_back(mp[x-1][y+1]); if(mp[x+1][y+1])t.push_back(mp[x+1][y+1]); if(mp[x][y+2])t.push_back(mp[x][y+2]); mp[x][y]=mp[x][y+1]=mex(t); } void p44(int x,int y){ p12(x,y); p12(x+1,y); p12(x+2,y+2); p12(x+3,y+2); p21(x+2,y); p21(x+2,y+1); p21(x,y+2); p21(x,y+3); } void p55(int x,int y){ p12(x,y+1); p12(x,y+3); p12(x+1,y+1); p12(x+4,y); p12(x+4,y+2); p21(x,y); p21(x+1,y+4); p21(x+2,y); p21(x+2,y+3); p21(x+3,y+4); } void p45(int x,int y){ p12(x,y+1); p12(x,y+3); p12(x+1,y+3); p12(x+2,y); p12(x+3,y); p12(x+3,y+2); p21(x,y); p21(x+1,y+2); p21(x+2,y+4); } void p54(int x,int y){ p21(x+1,y); p21(x+3,y); p21(x+3,y+1); p21(x,y+2); p21(x,y+3); p21(x+2,y+3); p12(x,y); p12(x+2,y+1); p12(x+4,y+2); } void p33(int x,int y){ p12(x,y); p21(x+1,y+2); } const char s7[7][8]={".aaeeff","b..gghh","b..iijj","cko....","cko....","dpq....","dpq...."}; int main(){ cin>>n; if(n<=2){puts("-1");return 0;} if(n==7){ for(int i=0;i<7;++i)puts(s7[i]); return 0; } if(n==11){ for(int i=1;i<=7;++i)for(int j=1;j<=7;++j)mp[i][j]=s7[i-1][j-1]-'a'+1; p44(8,8); } if(n%3==0){ for(int i=1;i<=n;i+=3){ for(int j=1;j<=n;j+=3){ p33(i,j); } } }else{ for(int i=0;i*5<=n;++i){ if((n-i*5)%4==0){ a=i,b=(n-i*5)/4; } } for(int i=0;i<a;++i){ for(int j=0;j<a;++j){ p55(i*5+1,j*5+1); } } for(int i=0;i<b;++i){ for(int j=0;j<b;++j){ p44(i*4+a*5+1,j*4+a*5+1); } } for(int i=0;i<a;++i){ for(int j=0;j<b;++j){ p54(i*5+1,j*4+a*5+1); } } for(int i=0;i<b;++i){ for(int j=0;j<a;++j){ p45(i*4+a*5+1,j*5+1); } } } for(int i=1;i<=n;++i)for(int j=1;j<=n;++j){ putchar(mp[i][j]?mp[i][j]+'a'-1:'.'); if(j==n)putchar('\n'); } return 0; }
#include <iostream> using namespace std ; long long int arr[60] ; int main() { long long int k ; cin >> k ; // vorodi if (k == 0) { cout << 2 << endl; cout << 1 << " " << 1; return 0; } for(int i = 0 ; i < 50 ; i++) arr[i] = i ; for(int i = 0 ; i < 50 ; i++) arr[i] += (k) / 50 ; if (k % 50 != 0) { for(int i = 0 ; i < k % 50 ; i++) { arr[i] += 50 ; for(int j = 0 ; j < 50 ; j++) if(j != i) arr[j]-- ; } } cout << 50 << endl ; for(int i = 0 ; i < 50 ; i++) cout << arr[i] << " " ; cout << endl ; return 0 ; }
0
#include <bits/stdc++.h> using namespace std; #define int long long int MOD = 1000000007; signed main(){ int N; string A,B,C; cin >> N >> A >> B >> C; int ans = 0; for(int i=0;i<N;i++){ if(A[i]==B[i] && B[i]==C[i]) ans += 0; else if(A[i]==B[i]||B[i]==C[i]||A[i]==C[i]) ans++; else ans += 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; //type #define ll long long typedef pair<int, int> P; //定数 #define INF 1000000000000 //10^12:∞ #define MOD 1000000007 //10^9+7:合同式の法 #define MAXR 100000 //10^5:配列の最大のrange //略記 #define PB push_back //挿入 #define MP make_pair //pairのコンストラクタ #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 #define Z class // OTHER // xの二乗を返す (関数テンプレート版) template <typename T> T square(T x) { return x * x; } #define chmax(x, y) (x = max(x, y)) #define chmin(x, y) (x = min(x, y)) // loop #define rep(i, n) for (int i = 0; i < (n); i++) #define REPD(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define FORD(i, a, b) for (ll i = a; i >= ll(b); i--) #define FORA(i, I) for (const auto &i : I) // vector #define ALL(x) x.begin(), x.end() // output #define YES() printf("YES\n") #define NO() printf("NO\n") #define isYES(x) printf("%s\n", (x) ? "YES" : "NO") #define Yes() printf("Yes\n") #define No() printf("No\n") #define ln cout << '\n' template <Z A> void pr(A a) { cout << a; ln; } template <Z A, Z B> void pr(A a, B b) { cout << a << ' '; pr(b); } int ans = 0; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * int main() { int a, b, c; cin >> a >> b >> c; pr((a + b + c) - max(a, max(b, c))); return 0; }
0
#include <iostream> int main(int argc, char const *argv[]) { int x, result; std::cin >> x; result = x*x*x; std::cout << result << "\n"; return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { // your code goes here int x; cin>>x; x=(int)(pow(x,3)); cout<<x<<endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; int main() { int n,m; cin >> n >> m; int l = n-1,r = 0; vector<P> ans; vector<bool> a(n+1,false); for (int i = 0;i < n/2;++i) { ans.push_back(make_pair(l,r)); a[l-r] = a[n-(l-r)] = true; l--;r++; if (a[l-r] || a[n-(l-r)] || l-r == n-l+r) { l--; while (l > r) { ans.push_back(make_pair(l,r)); l--;r++; } break; } } for (int i = 0;i < m;++i) cout << ans[i].first+1 << " " << ans[i].second+1 << newl; }
#include <iostream> #include <vector> using namespace std; int main(){ int A, B; cin >> A >> B; vector<vector<char>> c(100, vector<char>(100)); for (int i = 0; i < 50; i++){ for (int j = 0; j < 100; j++){ c[i][j] = '#'; } } for (int i = 50; i < 100; i++){ for (int j = 0; j < 100; j++){ c[i][j] = '.'; } } for (int i = 0; i < A - 1; i++){ c[i / 50 * 2][i % 50 * 2] = '.'; } for (int i = 0; i < B - 1; i++){ c[99 - i / 50 * 2][i % 50 * 2] = '#'; } cout << "100 100" << endl; for (int i = 0; i < 100; i++){ for (int j = 0; j < 100; j++){ cout << c[i][j]; } cout << endl; } }
0
#include <string> #include <vector> #include <sstream> #include <iostream> #include <algorithm> #include <map> #include <list> #include <set> #include <numeric> #include <queue> #include <stack> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <cstring> #include <climits> #include <cfloat> #include <ctime> #include <complex> #include <cassert> #include <iomanip> #include <tuple> using namespace std; typedef long long LL; typedef pair<int,int> P; void exec() { int edge[100][100]={0}; int n,k; cin >> n >> k; if(n==0&&k==0)exit(0); for(int i=0;i<k;i++){ int a,b,c; cin >> a >> b >> c; b--; c--; if(a==0){ priority_queue<P, vector<P>, greater<P> > q; q.push(P(0,b)); int dist[100]; fill(dist,dist+n,INT_MAX); dist[b]=0; while(q.size()){ int f=q.top().second; int d=q.top().first; q.pop(); if(f==c)break; if(dist[f]<d)continue; for(int j=0;j<n;j++){ if(edge[f][j]&&d+edge[f][j]<dist[j]){ dist[j]=d+edge[f][j]; q.push(P(dist[j],j)); } } } if(dist[c]!=INT_MAX){ cout << dist[c] << endl; } else { cout << -1 << endl; } } else { int d; cin >> d; if(edge[b][c]==0||d<edge[b][c]){ edge[b][c]=d; edge[c][b]=d; } } } } int main() { while(1)exec(); }
#include<cstdio> #include<iostream> #include<vector> #include<algorithm> #include<map> #include<set> #include<queue> #include<string> using namespace std; #define rep(i,n) for(int i=0;i<int(n);i++) #define reps(i,n) for(int i=1;i<=int(n);i++) #define sint(i) scanf("%d",&i); #define sintt(i,j) scanf("%d%d",&i,&j); #define sinttt(i,j,k) scanf("%d%d%d",&i,&j,&k); #define sintttt(i,j,k,m) scanf("%d%d%d%d",&i,&j,&k,&m); #define INF 1010000000 int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; class S{ public: int p,n; S(int p,int n):p(p),n(n){} bool operator<(const S& a)const{ return n>a.n; } }; ////////////djk////////////////////////////////////////// int main(){ while(1){ int n,m; sintt(n,m); if(n==0)break; vector<pair<int,int> > load[101]; rep(o,m){ int a; sint(a); if(a==1){ int b,c,d; sinttt(b,c,d); load[b].push_back(make_pair(c,d)); load[c].push_back(make_pair(b,d)); }else{ int s,g; sintt(s,g); priority_queue<S> que; que.push(S(s,0)); int visit[101]; rep(i,101)visit[i]=0; int ans=-1; while(1){ if(que.empty()==1){ break; } S u=que.top(); que.pop(); if(visit[u.p]==1){ continue; } visit[u.p]=1; if(u.p==g){ ans=u.n; break; } rep(i,load[u.p].size()){ que.push( S( load[u.p][i].first, u.n+load[u.p][i].second)); } } printf("%d\n",ans); } } } }
1
#include <bits/stdc++.h> using namespace std; int main(){ int N; int counter = 0; cin >> N; for(int i = 0;i < N/3 + 1;i++){ if((N - 3*(i + 1) >= 0)){ counter ++;} else cout << counter << endl;} }
//#include<bits/stdc++.h> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<set> #include<map> /* #include<boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/rational.hpp> namespace mp = boost::multiprecision; using Real = mp::number<mp::cpp_dec_float<1024>>; using Bint = mp::cpp_int; */ using namespace std; #define int long long #define REP(i,s,e) for((i)=(s);(i)<(e);(i)++) #define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--) #define FOR(i,n) for((i)=(0);(i)<(n);(i)++) #define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--) #define MOD 1000000007 signed main(){ double R; cin>>R; printf("%.12f\n",2*R*acos(-1)); }
0
#include<iostream> using namespace std; int main(){ int n; cin >> n; for (int i = 1; i <= n; i++) { if (i % 3 ==0 || i % 10 == 3 || (i/10)%10==3|| (i/100)%10==3 || (i/1000)%10==3){ cout << " " << i; } } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; struct edge { int to; // 辺の行き先 int weight; // 辺の重み edge(int t, int w) : to(t), weight(w) { } }; using Graph = vector<vector<int>>; using dou =long double; string yes="yes"; string Yes="Yes"; string YES="YES"; string no="no"; string No="No"; string NO="NO"; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define brep(n) for(int bit=0;bit<(1<<n);bit++) #define erep(i,container) for (auto i : container) #define irep(i, n) for(int i = n-1; i >= (int)0; i--) #define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++) #define reprep(i,j,h,w) rep(i,h)rep(j,w) #define all(x) (x).begin(),(x).end() #define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i]; #define pb push_back #define pf push_front #define lb lower_bound #define ub upper_bound #define fi first #define se second #define itn int #define mp make_pair #define sum(a) accumulate(all(a),0ll) #define keta fixed<<setprecision #define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a)) #define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a))); #define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) )); #define case std::cout <<"Case #" <<qqq+1<<": " #define res resize #define as assign #define ffor for(;;) #define ppri(a,b) std::cout << a<<" "<<b << std::endl #define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl #define aall(x,n) (x).begin(),(x).begin()+(n) typedef long long ll; typedef pair<int,int> P; //typedef long long T; const int INF = 2000000000; const ll INF64 = 922337203685477580ll; const ll MOD = 1000000007ll; const dou pi=3.141592653589793; int main(){ string s; std::cin >> s; int n; std::cin >> n; string ans; rep(i,s.size()){ if(i%n==0){ ans.pb(s[i]); } } std::cout << ans << std::endl; }
0
#include <iostream> #include <vector> using namespace std; int game(int num, int stone) { int i = 0, in_the_box = stone; vector<int> mayor(num, 0); while(1){ if(in_the_box != 0){ mayor[i] += 1; in_the_box -= 1; if(mayor[i] == stone){ break; } }else if(mayor[i] != 0){ in_the_box = mayor[i]; mayor[i] = 0; } i = (i + 1) % num; } return i; } int main(void) { int i, n, p, next_mayor; while(1){ cin >> n >> p; if(n == 0 && p == 0) break; next_mayor = game(n, p); cout << next_mayor << endl; } return 0; }
#include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); } putchar('\n'); } /* 6 abcdef aabbdd abcdef abbddd aabbdd 6 abcdef aabcde abcdef abcdee abcdde abccde abbcde aabcde */ int N; char S[1000111]; char T[1000111]; int C[1000111]; int off = 0, add = 0; void MAIN() { scanf("%d%s%s", &N, S, T); while (N > 0 && S[N-1] == T[N-1]) N--; memset(C, 0xc0, sizeof C); int pos = N-1; int ans = 0; for (int i=N-1; i>=0; ) { int j=i; while (j > 0 && T[j-1] == T[i]) j--; // T[j .. i]; int nxt = min(pos, j); while (nxt >= 0 && S[nxt] != T[i]) nxt--; if (nxt == -1) { puts("-1"); return; } off++; add++; for (int k=nxt; k<=pos; k++) C[k+off] = 1 - add; for (int k=j; k<=i; k++) amax(ans, C[k+off] + add); // REP (z, N) eprintf("%d ", C[z+off] + add); // eprintf("\n"); pos = nxt - 1; i = j-1; } printf("%d\n", ans); } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
0
#include <stdio.h> int main(void){ int A,B; scanf ("%d %d",&A,&B); if (B+2<=A) printf ("%d",A+(A-1)); if (A+2<=B) printf ("%d",B+(B-1)); else { if (A==B+1||B==A+1||A==B) printf ("%d",A+B); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int,int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define INF 1000000000 int main() { int a,b,ans; cin >> a >> b; ans = (a==b ? 2*a : 2*max(a,b)-1); cout << ans << endl; }
1
#include <stdio.h> int main() { int x,t; scanf("%d",&x); for(int i=2;i<=x;i++) { if(i%3==0)printf(" %d",i); else { t=i; while(1){ if(t%10==3){printf(" %d",i);break;} t=t/10; if(t==0)break; } } } printf("\n"); return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> p[8] = { {}, {}, {}, {"aa.", "..a", "..a"}, {"aabc", "ddbc", "bcaa", "bcdd"}, {"aabba", "bcc.a", "b..cb", "a..cb", "abbaa"}, {"aabc..", "ddbc..", "..aabc", "..ddbc", "bc..aa", "bc..dd"}, {"aabbcc.", "dd.dd.a", "..d..da", "..d..db", "dd.dd.b", "..d..dc", "..d..dc"} }; int main() { int n; cin >> n; if(n <= 2) { cout << -1 << '\n'; return 0; } vector<string> s(n, string(n, '.')); function<void(int, int, int)> draw = [&] (int x, int y, int w) { for(int i = 0; i < w; ++i) { for(int j = 0; j < w; ++j) { s[i + x][j + y] = p[w][i][j]; } } }; while(n >= 8) { draw(n - 4, n - 4, 4); n -= 4; } draw(0, 0, n); for(int i = 0; i < s.size(); ++i) { cout << s[i] << '\n'; } return 0; }
0
#include <bits/stdc++.h> using namespace std; #define finish(x) return cout << x << endl, 0 #define ll long long const int N = 100001; int n, m, col[N]; vector <int> v[N]; int dfs(int node, int pnode){ for(auto &i : v[node]){ if(col[i] != -1){ if(col[i] != (col[node] ^ 1)) return 1; } else{ col[i] = col[node] ^ 1; int f = dfs(i, node); if(f == 1) return 1; } } return 0; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); memset(col, -1, sizeof col); cin >> n >> m; for(int i = 0 ; i < m ; i++){ int x, y; cin >> x >> y; v[x].push_back(y); v[y].push_back(x); } col[1] = 0; if(dfs(1, 0)) finish(1LL * n * (n - 1) / 2 - m); int r = 0, b = 0; for(int i = 1 ; i <= n ; i++){ if(col[i] == 0) r++; else b++; } cout << 1LL * r * b - m << endl; }
#include <bits/stdc++.h> #define N 1000010 #define F first #define S second using namespace std; int n,m,book[N],nd; vector<pair<int,int> > ed[N]; vector<int> col[N],ng[N]; int main(){ int x,y,c,i,j,k; //memset(book,-1,sizeof(book)); cin>>n>>m; nd=n; for(i=0;i<m;i++) { cin>>x>>y>>c; x--; y--; ed[x].push_back(make_pair(c,y)); ed[y].push_back(make_pair(c,x)); col[c].push_back(x); col[c].push_back(y); } for(i=0;i<n;i++) { sort(ed[i].begin(),ed[i].end()); } for(i=0;i<N;i++) { for(j=0;j<col[i].size();j++) { y=col[i][j]; if(book[y]==i) { continue; } queue<int> q; q.push(y); book[y]=i; while(q.size()) { x=q.front(); q.pop(); ng[x].push_back(nd); ng[nd].push_back(x); for(k=lower_bound(ed[x].begin(),ed[x].end(),make_pair(i,0))-ed[x].begin();k<ed[x].size();k++) { if(ed[x][k].F!=i) { break; } if(book[ed[x][k].S]!=i) { book[ed[x][k].S]=i; q.push(ed[x][k].S); } } } nd++; } } /*for(i=0;i<n;i++) { for(j=0;j<ng[i].size();j++) { cout<<i<<"->"<<ng[i][j]<<endl; } }*/ queue<int> q,st; q.push(0); st.push(0); book[0]=-2; while(q.size()) { x=q.front(); y=st.front(); q.pop(); st.pop(); if(x==n-1) { cout<<y/2<<endl; return 0; } for(i=0;i<ng[x].size();i++) { c=ng[x][i]; if(book[c]==-2) { continue; } book[c]=-2; q.push(c); st.push(y+1); } } cout<<-1<<endl; return 0; }
0
#include<stdio.h> #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int mod = 1e9+7; void ad(int &x,int y) { x+=y; if(x>=mod)x-=mod; } int zy[8][2] = {{6,1},{3,2},{2,2},{4,1},{3,3},{6,1},{7,5},{6,6}}; char ss[300005]; int n; int dp[300005][8]; int main() { scanf("%s",&ss[1]); n = strlen(ss+1); dp[0][0] = 1; for(int i=0;i<n;i++) { for(int j=0;j<8;j++) { if(ss[i+1]!='0') ad(dp[i+1][zy[j][1]],dp[i][j]); if(ss[i+1]!='1') ad(dp[i+1][zy[j][0]],dp[i][j]); } } int ans = (dp[n][1] + dp[n][2])%mod; printf("%d",ans); }
#include<cstdio> #include<cstring> #define mod 1000000007 #define ran 333333 char s[ran];int n; int a[ran],p2[ran]; int dp[3],dp2[3]; int add(int x,int y){ return (x+=y)<mod?x:x-mod; } void addto(int&x,int y){ x =add(x,y); } int mul(int x,int y){ return (int)((long long int)x*y%mod); } const int trans[3][4]={ {0,1,0,1}, {0,1,2,3}, {2,2,2,3} }; int main(){ scanf("%s",s); n = strlen(s); if(n == 1){ printf("%d\n",s[0]=='0'?0:1); return 0; } p2[0] = 1;for(int i=1; i<=n; i++)p2[i] = add(p2[i-1],p2[i-1]); for(int i=n-1; i>=0; i--)a[i] = a[i+1] + (s[i] == '?'); int res = 0; for(int i=0; i<n-1; i+=2){ dp2[0] = dp2[1] = dp2[2] = 0; for(int c1=0; c1<2; c1++)if(s[i] == '?' || s[i] == c1 + '0') for(int c2=0; c2<2; c2++)if(s[i+1] == '?' || s[i+1] == c2 + '0'){ int T = c1 * 2 + c2; if(i==0){ if(T == 3)addto(res, p2[a[i+2]]);else addto(dp2[T], 1); }else{ for(int k=0; k<3; k++) if(trans[k][T] == 3) addto(res, mul(dp[k],p2[a[i+2]])); else addto(dp2[trans[k][T]], dp[k]); } } dp[0] = dp2[0]; dp[1] = dp2[1]; dp[2] = dp2[2]; } if(s[n-1] == '?' || s[n-1] == '1'){ addto(res,dp[1]); addto(res,dp[2]); } printf("%d\n",res); return 0; }
1
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <sstream> #include <cmath> #include <queue> using namespace std; int main(){ int n, m; while(true){ cin >> n >> m; if(n == 0 && m == 0){ break; } int p[200000]; long long int sum = 0; for(int i = 0; i < n; i++){ cin >> p[i]; sum += p[i]; } sort(p, p + n); for(int i = n - m; i >= 0; i -= m){ sum -= p[i]; } cout << sum << endl; } return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { int N, M; cin >> N >> M; vector<int> A(N); REP(i, 0, N) cin >> A[i]; int modsum = 0; unordered_map<int, int> m; REP(i, 0, N) { modsum = (modsum + A[i]) % M; m[modsum]++; } ll ans = 0; modsum = 0; REP(i, 0, N) { ans += m[modsum]; modsum = (modsum + A[i]) % M; m[modsum]--; } cout << ans << endl; return 0; }
0
#include<iostream> #include<cmath> using namespace std; int main(){ double x1, x2, y1, y2, dis; cin >> x1 >> y1 >> x2 >> y2; dis = sqrt(pow(x2 - x1,2.0) + pow(y2 - y1,2.0)); cout << fixed << dis <<endl; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <cmath> #include <numeric> #include <iomanip> #include <stack> #include <complex> #include <functional> #include <tuple> using namespace std; #define Rep(i,a,b) for(ll i = a; i < b; ++i) #define rep(i,b) Rep(i,0,b) #define allof(a) (a).begin(), (a).end() #define Yes(q) ((q) ? "Yes" : "No") #define YES(q) ((q) ? "YES" : "NO") #define Possible(q) ((q) ? "Possible" : "Impossible") #define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE") using ll = long long; constexpr int inf = 1e9 + 7; constexpr ll infll = 1ll << 60ll; constexpr ll mod = 998244353; // 0~3までは右下左上 4~7までは斜め constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 }; constexpr int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1 }; namespace { template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } void Cout(long long x, const char* end = "\n") { std::cout << x << end; } template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; } template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } } // 標準入出力 struct inp { std::size_t szi, szj; inp(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {} template <typename T> operator T () const { T a; std::cin >> a; return a; } template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; } template <typename T> operator std::vector<std::vector<T>>() const { std::vector<std::vector<T>> a(szi, std::vector<T>(szj)); for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a; } }; inp inp1; } int main() { string s = inp1; s = '0' + s; int n = s.size(); vector<vector<int>> dp(n + 1, vector<int>(2, inf)); dp[0][0] = 0; rep(i, n) { int num = s[i] - '0'; // ピッタリ払う chmin(dp[i + 1][0], dp[i][0] + num); chmin(dp[i + 1][0], dp[i][1] + 10 - num); // 余分に払う chmin(dp[i + 1][1], dp[i][0] + num + 1); chmin(dp[i + 1][1], dp[i][1] + 10 - num - 1); } Cout(dp[n][0]); return 0; }
0
#include <iostream> #include <string> using namespace std; int main(){ string str; //string reverse=""; cin>>str; for (int i=str.length()-1; i>-1; i--){ cout<<str.at(i); } cout<<endl; //cout<<reverse<<endl; return 0; }
#include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> //namespace mp = boost::multiprecision; using namespace std; const double PI = 3.14159265358979323846; typedef long long ll; const double EPS = 1e-9; #define rep(i, n) for (int i = 0; i < (n); ++i) //#define rep(i, n) for (ll i = 0; i < (n); ++i) typedef pair<ll, ll> P; const ll INF = 10e17; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) #define ret() return 0; double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; } std::istream &operator>>(std::istream &in, set<int> &o) { int a; in >> a; o.insert(a); return in; } std::istream &operator>>(std::istream &in, queue<int> &o) { ll a; in >> a; o.push(a); return in; } bool contain(set<int> &s, int a) { return s.find(a) != s.end(); } //ofstream outfile("log.txt"); //outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl; // std::cout << std::bitset<8>(9); //const ll mod = 1e10; typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK; // 借りました。 // https://kenkoooo.hatenablog.com/entry/2019/12/29/110321 const vector<vector<char>> s3 = vector<vector<char>>{ {'a', 'a', '.',}, {'.', '.', 'a',}, {'.', '.', 'a',}, }; const vector<vector<char>> s4 = vector<vector<char>>{ {'a', 'b', 'e', 'e'}, {'a', 'b', 'f', 'f'}, {'g', 'g', 'c', 'd'}, {'h', 'h', 'c', 'd'}, }; const vector<vector<char>> s5 = { {'a', 'c', 'd', '.', '.'}, {'a', 'c', 'd', '.', '.'}, {'b', 'f', 'f', 'g', 'g'}, {'b', '.', 'e', 'h', 'h'}, {'i', 'i', 'e', 'j', 'j'}, }; const vector<vector<char>> s6 = { {'a', 'd', 'g', 'g', '.', '.'}, {'a', 'd', 'h', 'h', '.', '.'}, {'b', 'e', 'i', 'i', '.', '.'}, {'b', 'e', '.', '.', 'j', 'j'}, {'c', 'f', '.', '.', 'k', 'k'}, {'c', 'f', '.', '.', 'l', 'l'}, }; const vector<vector<char>> s7 = { {'a', 'd', 'f', '.', '.', '.', '.'}, {'a', 'd', 'f', '.', '.', '.', '.'}, {'b', 'e', 'g', '.', '.', '.', '.'}, {'b', 'e', 'g', '.', '.', '.', '.'}, {'c', '.', '.', 'h', 'h', 'i', 'i'}, {'c', '.', '.', 'j', 'j', 'k', 'k'}, {'.', 'l', 'l', 'm', 'm', 'n', 'n'}, }; P solve(int n) { rep(i, 1000) { int x = i; int y = n - (4 * x); if (y == 5) { return {x, y}; } if (y == 6) { return {x, y}; } if (y == 7) { return {x, y}; } if (y == 0) { return {x, y}; } } __throw_runtime_error("konaide"); } void copy_print(vector<vector<char>> &ans, int n, const vector<vector<char>> &from, int sy, int sx) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans[sy + i][sx + j] = from[i][j]; } } } void print(const vector<vector<char>> &ans) { for (auto &line: ans) { for (char e : line) cout << e; cout << endl; } } int main() { int n; cin >> n; if (n == 2) { cout << -1 << endl; ret(); } if (n == 3) { print(s3); ret(); } P p = solve(n); vector<vector<char>> ans(n, vector<char>(n, '.')); rep(i, p.first) { int sy = 4 * i; int sx = 4 * i; copy_print(ans, 4, s4, sy, sx); } if (p.second == 5) { int sy = p.first * 4; int sx = p.first * 4; copy_print(ans, 5, s5, sy, sx); } if (p.second == 6) { int sy = p.first * 4; int sx = p.first * 4; copy_print(ans, 6, s6, sy, sx); } if (p.second == 7) { int sy = p.first * 4; int sx = p.first * 4; copy_print(ans, 7, s7, sy, sx); } print(ans); }
0
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define MIN(a,b) ((a)>(b)? (b): (a)) #define MAX(a,b) ((a)<(b)? (b): (a)) const long long INF = 1LL << 60; typedef unsigned long long ll; const long long MOD = 1000000000 + 7; int main(){ ll n; cin >> n; vector<ll> sq; ll cnt = 1; while (cnt * cnt <= n) { sq.push_back(cnt*cnt); cnt++; } sort(sq.begin(), sq.end()); cout << sq[sq.size() - 1] << endl; return 0; }
#include<iostream> using namespace std; int main(){ int a;cin>>a; if(a<112)cout<<111<<endl; else if(a<223)cout<<222<<endl; else if(a<334)cout<<333<<endl; else if(a<445)cout<<444<<endl; else if(a<556)cout<<555<<endl; else if(a<667)cout<<666<<endl; else if(a<778)cout<<777<<endl; else if(a<889)cout<<888<<endl; else cout<<999<<endl; }
0
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; const int mod = 998244353; int main() { int n, d0; cin >> n >> d0; if(d0 != 0) { cout << 0 << endl; return 0; } vector<int> d(100005); d.at(0) = 1; int max_d = 0; for(int i = 1; i < n; ++i) { int di; cin >> di; max_d = max(max_d, di); d.at(di)++; } if(d.at(0) != 1) { cout << 0 << endl; return 0; } ll ans = 1; int i = 1; while(i < n) { if(d.at(i) == 0) break; rep(j, d.at(i)) { ans *= d.at(i-1); ans %= mod; } ++i; } if(i < max_d) cout << 0 << endl; else cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int main() { int n; cin >> n; map<int, long long> d; for(int i = 0; i < n; i++){ int a; cin >> a; if(i == 0 && a != 0){ cout << 0 << endl; return 0; } d[a]++; } long long sum = 0, ans = 1, last = 1; bool ok = false; for(int i = 0; i < n; i++){ if(sum == n){ ok = true; break; } else if(!d.count(i)) break; if(d.at(0) > 1) break; long long now = d.at(i); sum += now; long long mul = 1; for(int i = 0; i < now; i++){ mul *= last; mul %= mod; } ans *= mul; ans %= mod; last = now; if(sum == n) ok = true; } if(!ok) ans = 0; cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i) #define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i) #define per(i,N) for(int i=(N)-1;i>=0;--i) #define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i) #define all(arr) (arr).begin(), (arr).end() #define SP << " " << #define SPF << " " #define SPEEDUP cin.tie(0);ios::sync_with_stdio(false); #define MAX_I INT_MAX //1e9 #define MIN_I INT_MIN //-1e9 #define MAX_UI UINT_MAX //1e9 #define MAX_LL LLONG_MAX //1e18 #define MIN_LL LLONG_MIN //-1e18 #define MAX_ULL ULLONG_MAX //1e19 typedef long long ll; typedef pair<int,int> PII; typedef pair<char,char> PCC; typedef pair<ll,ll> PLL; typedef pair<char,int> PCI; typedef pair<int,char> PIC; typedef pair<ll,int> PLI; typedef pair<int,ll> PIL; typedef pair<ll,char> PLC; typedef pair<char,ll> PCL; inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;} inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;} inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;} int main(void){ SPEEDUP cout << setprecision(15); int N;cin >> N; string s;cin >> s; map<pair<string,string>,int> mp; rep(n,1<<N){ string t,u; rep(i,N){ if((n>>i)&1) t.push_back(s[i]); else u.push_back(s[i]); } ++mp[make_pair(t,u)]; } reverse(all(s)); ll ans = 0; rep(n,1<<N){ string t,u; rep(i,N){ if((n>>i)&1) t.push_back(s[i]); else u.push_back(s[i]); } if(mp.count(make_pair(t,u))) ans += mp[make_pair(t,u)]; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> typedef long long int ll; using namespace std; int main() { const ll M = 998244353; ll N, ans = 1; cin >> N; vector<ll> d; vector<ll> cnt(N, 0); for (ll i = 0; i < N; i++) { ll x; cin >> x; if (i == 0) { if (x != 0) ans = 0; } else { d.push_back(x); } cnt[x]++; } for (auto x : d) { if (x > 0) ans *= cnt[x-1]; else ans = 0; ans %= M; } cout << ans << endl; return 0; }
0
# define _CRT_SECUREj_NO_WARNINGS 1 # define _USE_MATH_DEFINES # include <iostream> # include <numeric> # include <string> # include <bitset> # include <vector> # include <algorithm> # include <cstdlib> # include <cstdio> # include <cstring> # include <cstdlib> # include <iomanip> # include <queue> # include <sstream> # include <climits> # include <cmath> # include <list> # include <functional> # include <string> # include <ctime> # include <set> # include <forward_list> # include <map> # include <stack> using namespace std; # define INF ((int)(1<<25)) # define REP(i,n) for(int i=0;i<(int)n;i++) # define FOR(i,n) REP(i,n) # define FORI(i,k,n) for(int i=k;i<(int)n;i++) # define TORAD 2.0*M_PI/360.0 # define INT(x) int x;cin>>x; # define ALL(x) (x).begin(),(x).end() # define RALL(x) (x).rbegin(),(x).rend() # define DEBUG(x) cout<<#x<<":"<<x<<endl; # define EPS 1e-12 #ifdef _MSC_VER #include <intrin.h> #define __builtin_popcount __popcnt #endif #define int long long typedef long long lint; typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> pii; typedef pair<int, pii> piii; const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 }; template<class T> void debug(T a) { for (auto i : a)cout << i << endl; } const int M = 110; int f[M][M]; int v, e, r; signed main() { cin >> v >> e; FOR(i, M)FOR(j, M)f[i][j] = INT_MAX; FOR(i, M)f[i][i] = 0; FOR(i, e) { int s, t, d; cin >> s >> t >> d; f[s][t] = d; } FOR(k, M) { FOR(i, M) { FOR(j, M) { if (f[i][k] == INT_MAX || f[k][j] == INT_MAX)continue; f[i][j] = min(f[i][j], f[i][k] + f[k][j]); } } } FOR(i, M)if (f[i][i] < 0) { cout << "NEGATIVE CYCLE" << endl; return 0; } FOR(i, v) { FOR(j, v) { if (j)cout << " "; if (f[i][j] == INT_MAX)cout << "INF"; else cout << f[i][j]; } cout << endl; } }
#include <stdio.h> #include <limits.h> int main(){ int n,m,s,i,j; scanf("%d%d",&n,&m); int e[m+1][3],dist[m+1],update=1,k,d[200][200]; //printf("xxx"); for(i=0;i<n;i++){ for(j=0;j<n;j++){ if(i==j)d[i][j]=0; else d[i][j]=INT_MAX; } } for(i=0;i<m;i++){ for(j=0;j<3;j++){ scanf("%d",&e[i][j]); } d[e[i][0]][e[i][1]]=e[i][2]; } for(i=0;i<n;i++){ dist[i]=INT_MAX; } dist[s]=0; for(i=0;i<n-1;i++){ update=0; for(j=0;j<m;j++){ if(dist[e[j][0]]!=INT_MAX&&dist[e[j][1]]>dist[e[j][0]]+e[j][2]){ dist[e[j][1]]=dist[e[j][0]]+e[j][2]; update=1; } } if(update==0)break; } for(j=0;j<m;j++){ if(dist[e[j][0]]!=INT_MAX&&dist[e[j][1]]>dist[e[j][0]]+e[j][2]){ printf("NEGATIVE CYCLE\n"); return 0; } } for(k=0;k<n;k++){ for(i=0;i<n;i++){ for(j=0;j<n;j++){ if((d[i][k]!=INT_MAX&&d[k][j]!=INT_MAX)&&d[i][j]>d[i][k]+d[k][j]){ d[i][j]=d[i][k]+d[k][j]; } } } } for(i=0;i<n;i++){ for(j=0;j<n;j++){ if(j>0)printf(" "); if(d[i][j]==INT_MAX){ printf("INF"); } else{ printf("%d",d[i][j]); } } printf("\n"); } return 0; }
1
#include <iostream> #include <vector> using namespace std; typedef long long ll; int main() { string s; cin >> s; int l = s.length(); if (s.find("AC") != string::npos) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <iostream> #include <numeric> #include <math.h> #include <algorithm> #include <float.h> #include <limits> #include <vector> #include <string.h> #include <iomanip> #define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++) #define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--) #define MOD 1000000007 #define INF 2147483647 #define ll long long #define asort(a) sort(a.begin(),a.end());//昇順ソート #define usort(a) sort(a.rbegin(),a.rend());//降順ソート using namespace::std; int jo(ll int a, ll int b){//累乗 ll int num=1; rep(i,0,b) num=num*a; return num; } char tobig(char s){//char大文字化 return (s-0x20); } char tolow(char s){//char小文字化 return (s+0x20); } int ctoi(char a){//char->int if('0'<=a&&a<='9') return (a-'0'); return -1; } int gcd(ll int a,ll int b) {//最大公約数 if(a<b) return gcd(b,a); int c; while ((c=a%b)) { a=b; b=c; } return b; } int lcm(ll int a,ll int b){//最小公倍数 return (a*b)/gcd(a,b); } int main(){ string S;cin>>S; int AC=0; rep(i,0,S.length()-1){ if(S[i]=='A'&&S[i+1]=='C') AC++; } cout<<(AC?"Yes":"No"); } // vector<vector<int>> 変数名(左の個数, vector<int>(右の個数)); //cout<<fixed<<setprecision(n); //小数点n桁まで表示 // vector<pair<int,int>> data(N); //2つのデータを格納、.first/.secondで参照 // pairのソートはfirst優先の昇順
1
#include <bits/stdc++.h> #define rep(i, z, n) for(int i = z; i < n; i++) #define all(v) v.begin(), v.end() typedef long long ll; //const int INF = 1<<29; //const int MODINF = 1000000007; using namespace std; int main(){ int N; cin >> N; vector<int> A(N + 2, 0); int sum = 0; rep(i, 1, N + 1) cin >> A.at(i); rep(i, 0, N + 1) sum += abs(A.at(i + 1) - A.at(i)); rep(i, 1, N + 1){ int x = A.at(i - 1); int y = A.at(i); int z = A.at(i + 1); if ((x - y)*(y - z) >= 0){ cout << sum << endl; } else{ cout << sum - 2 * min(abs(x - y), abs(y - z)) << endl; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; vector<int> a(n, 0); vector<ll> ans(n, 0); ll fee = 0; for (ll i = 0; i < n; i++) { cin >> a[i]; } ll tmp = 0; for (ll i = 0; i < n + 1; i++) { if (i == n) { fee += abs(tmp - 0); break; } fee += abs(tmp - a[i]); tmp = a[i]; } for (ll i = 0; i < n; i++) { ans[i] = fee - (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i])) + (abs(a[i + 1] - a[i - 1])); } for (ll i = 0; i < n; i++) { cout << ans[i] << endl; } }
1
#include<stdio.h> #include<string.h> #include<iostream> #include <fstream> #include<iostream> #include <sstream> #include<string> #include <list> using namespace std; const int M = 1003; const int INIT = (M*M + 1); int C[M][M];// = { 0 }; int countmatchstring(const char* p1, const char*p2, int length1, int length2,int x, int y, int i, int j,int cost) { int w = (i - 1 > j - 1) ? i - 1 : j - 1; if (p1[x + i] == p2[y + j]) { x = x + i; y = y + j; if (x == length1 - 1 && y == length2 - 1) { C[x][y] = 0; return w; } if (x == length1 - 1 || y == length2 - 1) { while (1); } C[x][y] = countmatchstring(p1, p2, length1, length2, x, y, 1, 1, w + cost); return w + C[x][y]; } if (C[x + i][y + j] == INIT) { int c1 = INIT, c2 = INIT,c3 = INIT; if (x + i + 1 < length1) { for (int p = 1; x + i + p < length1; ++p) { if (p1[x + i + p] == p2[y + j]) { c1 = countmatchstring(p1, p2, length1, length2, x, y, i + p, j, cost); break; } } } if (y + j + 1 < length2) { for (int q = 1; y + j + q < length2; ++q) { if (p1[x + i] == p2[y + j + q]) { c2 = countmatchstring(p1, p2, length1, length2, x, y, i, j + q, cost); break; } } } if ((x + i + 1 < length1) && (y + j + 1 < length2)) { c3 = countmatchstring(p1, p2, length1, length2, x, y, i + 1, j + 1, cost); } int c = (c1 < c2 ? c1 : c2); c = (c < c3 ? c : c3); C[x + i][y + j] = c; } return C[x + i][y + j]; } int main(){ std::istream & c_in = cin; for (int i = 0; i < M; ++i){ for (int j = 0; j < M; ++j){ C[i][j] = INIT; } } string s1, s2; getline(c_in, s1); getline(c_in, s2); s1 = "A" + s1 + "B"; s2 = "A" + s2 + "B"; const char* p1 = s1.c_str(); const char* p2 = s2.c_str(); countmatchstring(p1, p2, s1.length(), s2.length(),0, 0, 1,1,0); printf("%d\n", C[1][1]); return 0; }
#include<iostream> #include<iomanip> #include<vector> #include<algorithm> #include<string> #include<map> using namespace std; typedef long long ll; #define INF (1 << 30) #define MOD 1000000007 template<class T> inline void chmax(T& a, T b) { if (a < b) a = b; } template<class T> inline void chmin(T& a, T b) { if (a > b) a = b; } class Combination { vector<ll> fact, finv; public:Combination(int n) { fact.resize(n + 1, 1); finv.resize(n + 1, 1); vector<ll> inv(n + 1, 1); for (int i = 2; i <= n; ++i) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } public:ll comb(int n, int k) { return fact[n] * (finv[n - k] * finv[k] % MOD) % MOD; } }; map<int, int> factorize(int x) { map<int, int> m; for (int i = 2; i * i <= x; ++i) { while (x % i == 0) { x = x / i; ++m[i]; } } if (x != 1) { ++m[x]; } return m; } int main() { int N, M; cin >> N >> M; auto m = factorize(M); auto C = Combination(N + 100); ll ans = 1; for (auto i : m) { ans *= C.comb(N + i.second - 1, i.second); ans = ans % MOD; } cout << ans << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; #define MOD 1000000007 #define BIG 1000000010 #define repi(i,x,n) for(int i=x;i<n;i++) #define rep(i,n) repi(i,0,n) #define repn(i,n) for(int i=n;i>=0;i--) typedef long long int ll; int main(){ int n; int k[100]; int num; string s; string ans; int alp[52]; rep(i,52){ if(i<26) alp[i]=i+65; else alp[i]=i+71; } while(1){ cin>>n; if(n==0) break; rep(i,n){ cin>>k[i]; } cin>>s; ans="0"; rep(i,s.size() ){ rep(j,52){ if(alp[j]==s[i]) num=j; } int a=(num-k[i%n]+520)%52; //cout<<a<<endl; ans+=alp[a]; //cout<<ans<<endl; } repi(i,1,ans.size()){ cout<<ans[i]; } cout<<endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ int N,Q; while( cin >> N >> Q, N||Q ){ vector<int> date(100, 0); for(int i = 0; i < N; i++){ int m; cin >> m; for(int j = 0; j < m; j++){ int a; cin >> a; date[a] += 1; } } int most_conv, max_v = 0; for(int i = 0; i < 100; i++){ if( date[i] > max_v ){ most_conv = i; max_v = date[i]; } } if( max_v >= Q ) cout << most_conv << endl; else cout << 0 << endl; } return 0; }
0
#include <stdio.h> #include <string.h> int main(void) { int i, j; int n; int len; char str[1024]; scanf("%d\n", &n); for (j = 0; j < n; j++){ fgets(str, 1024, stdin); len = strlen(str); for (i = 0; i < len; i++){ if (strncmp(&str[i], "Hoshino", 7) == 0){ strncpy(&str[i], "Hoshina", 7); } } printf("%s", str); } return (0); }
#include <algorithm> #include <cmath> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <cassert> #include <functional> using namespace std; #define LOG(...) printf(__VA_ARGS__) //#define LOG(...) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define REP(i,n) for(int i=0;i<(int)(n);++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) #define RSORT(c) sort((c).rbegin(),(c).rend()) #define CLR(a) memset((a), 0 ,sizeof(a)) typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 }; int main() { int n; string sn; getline(cin, sn); n = atoi(sn.c_str()); REP(i, n){ string s; getline(cin, s); while (s.find("Hoshino") != string::npos){ s[s.find("Hoshino") + 6] = 'a'; } cout << s << endl; } }
1
#include <bits/stdc++.h> using namespace std; int main() { int n,m,A,B; scanf("%d %d %d %d",&n,&m,&A,&B); for(int i=0;i<B;i++) { for(int j=0;j<m;j++) printf("%c",j<A?'0':'1'); puts(""); for(int j=0;j<m;j++) printf("%c",j<A?'1':'0'); puts(""); } for(int i=0;i<n-2*B;i++) { for(int j=0;j<m;j++) printf("%c",j<A?'0':'1'); puts(""); } }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,k,m,mk; cin>>a>>b>>c>>k; m=max({a,b,c}); mk=m; for(int i=0; i<k; i++) mk*=2; cout<<a+b+c-m+mk; }
0
#include<iostream> #include<vector> #include<string.h> #include<queue> using namespace std; const int N = 1e5 + 7; string x[3] = { "RGB","GBR","BRG" }; int y[3][N]; int main() { int n, k; while (cin >> n >> k) { cout << n - k + 1 << '\n'; } return 0; }
#include <iostream> using namespace std; int main() { char input[1000]; while (cin >> input) { char pre = '0'; int output = 0; for (int i = 0; input[i] != '\0'; i++) { switch (input[i]) { case 'M': output += (pre == 'C') ? 800 : 1000; break; case 'D': output += (pre == 'C') ? 300 : 500; break; case 'C': output += (pre == 'X') ? 80 : 100; break; case 'L': output += (pre == 'X') ? 30 : 50; break; case 'X': output += (pre == 'I') ? 8 : 10; break; case 'V': output += (pre == 'I') ? 3 : 5; break; case 'I': output++; break; } pre = input[i]; } cout << output << endl; } }
0
#include <algorithm> #include <cmath> #include <vector> #include <functional> #include <cstdlib> #include <map> #include <set> #include <iostream> #include <string> #include <ctype.h> #include <climits> #include <queue> #include <iomanip> using namespace std; typedef long long ll; #define REP(i, n) for(ll i = 0; i < (ll)(n); ++i) template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;} template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;} int main(){ ll n; cin >> n; vector<ll> a(n), b(n), c(n); REP(i,n) cin >> a[i]; REP(i,n) cin >> b[i]; REP(i,n) cin >> c[i]; sort(a.begin(),a.end()); sort(b.begin(),b.end()); sort(c.begin(),c.end()); vector<ll> B(n),SB(n+1); REP(i,n){ if(b[i] >= c[n-1]){ B[i] = 0; continue; } int ok,ng,mid; ok = 1; ng = n+1; while(abs(ok-ng)>1){ mid = (ok+ng)/2; if(b[i]<c[n-mid]){ ok = mid; }else{ ng = mid; } } B[i] = ok; } SB[n]=0; for(int i=n-1; i>=0; i--) SB[i] = SB[i+1]+B[i]; vector<ll> A(n); REP(i,n){ if(a[i] >= b[n-1]){ A[i] = 0; continue; } int ok,ng,mid; ok = 1; ng = n+1; while(abs(ok-ng)>1){ mid = (ok+ng)/2; if(a[i]<b[n-mid]){ ok = mid; }else{ ng = mid; } } A[i] = SB[n-ok]; } ll ans = 0; REP(i,n) ans += A[i]; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N; int A[3][100001]; LL dp[3][100001] = {}; int main() { scanf("%d", &N); rep(j, 3) { rep(i, N) scanf("%d", &A[j][i]); A[j][N] = 1000000001; } rep(j, 3) sort(A[j], A[j] + N); rep(i, N + 1) dp[0][i] = i; rep(j, 2) { int p = 0; rep(i, N) { while (A[j][p] < A[j + 1][i]) p++; dp[j + 1][i + 1] += dp[j + 1][i] + dp[j][p]; } } printf("%lld\n", dp[2][N]); return 0; }
1
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0;i<(n);++i) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define all(x) (x).begin(), (x).end() #define PI 3.14159265358979323846264338327950L using namespace std; typedef long long ll; typedef long double ld; int main() { int n,k; cin>>n>>k; vector<int> l(n); rep(i,n) cin>>l[i]; sort(all(l)); int ans=0; rep(i,k) ans+=l[n-1-i]; cout<<ans; }
#include <iostream> #include <algorithm> #include <iomanip> #include <string> #include <vector> #include <math.h> #include <queue> #include <deque> #include <stack> #include <map> const int MOD = 1e9+7; #define PI 3.14159265359 typedef long long ll; using namespace std; int main(){ int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++){ cin >> v[i]; } ll ans = 0; for (int all = 0; all <= min(k, n); all++){ for (int i = 0; i <= all; i++){ int l = i, r = all - i; int rem = k - all; priority_queue<int, vector<int>, greater<int> > que; for (int j = 0; j < l; j++){ que.push(v[j]); } for (int j = 0; j < r; j++){ que.push(v[n-j-1]); } ll tmp = 0; while (!que.empty()){ if (que.top() < 0 && rem > 0){ rem--; que.pop(); }else{ tmp += que.top(); que.pop(); } } ans = max(ans, tmp); } } cout << ans << endl; return 0; }
0
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll u(ll a, ll b){ if(a%b==0) return b; else return u(b,a%b); } //素数判別じゃなかったです //ll s( ll n){ // bool k[n+1]={}; // ll ans=0; // for(ll i=2; i<n; i++){ // if(!k[i]){ // ll d=i; // if(n%i==0){ // ans++; // cout<<i<<endl; // } // //cout<<i<<" "<<ans<<endl; // while(d<=n){ // k[d]=true; // d+=i; // } // } // ///cout<<ans<<endl; // } // //cout<<ans<<endl; // return ans; //} int main(){ ll n,a,b; cin>>a>>b; n=u( max(a,b),min(a,b)); //cout<<n<<endl; ll ans=1; ll k=2; //ans+=s(n); //ルートn以上の素因数は1コまで while(n>=k*k){ if(n%k==0) ans++; while(n%k==0){ n/=k; } //cout<<n<<endl; k++; } if(n>1){ ans++; } //cout<<n<<endl; cout<< ans <<endl; }
#include<bits/stdc++.h> #define rep(i,f,n) for(ll i=(f); (i) < (n); i++) #define repe(i,f,n) for(ll i=(f); (i) <= (n); i++) using namespace std; using ll = long long; #define MOD (ll)1000000007 #define PI 3.14159265359 #define debug(x) cout<<#x<<" :: "<<x<<"\n"; #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"; #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"; //#define P pair<ll, ll> //printf("%.10f\n") //cout << fixed << setprecision(10); template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;} template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;} ll INF = 1e+18; int iINF = 1e9; int main() { int N, M; cin >> N >> M; if(M % N == 0){ cout << M / N << endl; return 0; } int maxi = 1; rep(i, 1, M/N){ int d = i; if((M - (d * (N - 1))) % d == 0) maxi = i; } cout << maxi << endl; }
0
/* Loading:{ https://codeforces.com/problemset/problem/1234/F } */ #include <bits/stdc++.h> using namespace std; #define ll int // optimize with int #define endl '\n' const int N = 1e6 + 5; ll a[305]; ll dp[305][305][305]; // id, used to donate, used to receive; ll mod = 998244353; // fucking mod 1e9 + 7 ll n, k, cnt = 0; ll add(ll x, ll y){ // optimize with add func ll res = x + y; if (res >= mod) res -= mod; return res; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("GUARDS.INP", "r")){ freopen("GUARDS.INP", "r", stdin); freopen("GUARDS.OUT", "w", stdout); } string s; cin >> s; n = s.length(); cin >> k; ll cur = 0; ll cnt1 = 0; for (int i = s.length() - 1; i >= 0; i--){ if (s[i] == '1') { cur++; cnt1++; } else { cnt++; a[cnt] = cur; cur = 0; } } cnt++; a[cnt] = cur; //memset(dp, -1, sizeof(dp)); k = min(k, cnt1); for (int i = a[1]; i >= max(0, a[1] - k); i--){ dp[1][a[1] - i][0] = 1; } ll sum = a[1]; for (int i = 1; i < cnt; i++){ for (int j = 0; j <= sum; j++){ for (int t = 0; t <= j; t++){ dp[i + 1][j][t] = add(dp[i + 1][j][t], dp[i][j][t]); for (int x = a[i + 1] - 1; x >= max(0, (a[i + 1] - (k - j))); x--){ dp[i + 1][j + a[i + 1] - x][t] = add(dp[i + 1][j + a[i + 1] - x][t], dp[i][j][t]); } for (int x = a[i + 1] + 1; x <= a[i + 1] + (j - t); x++){ dp[i + 1][j][t + x - a[i + 1]] = add(dp[i + 1][j][t + x - a[i + 1]], dp[i][j][t]); } } } sum += a[i + 1]; } ll ans = 0; for (int i = 0; i <= k; i++) { ans = add(ans, dp[cnt][i][i]); //cout << dp[cnt][i][i] << " "; } cout << ans; }
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; typedef long long ll; constexpr ll mod = 998244353; ll dp[301][301][301] = {},dp2[301][301] = {},dp3[301][301] = {}; vector<int> v; int main(){ int i,j,k,l,r; string s; cin >> s >> k; s.push_back('0'); int n = s.size(); for(i=0;i<n;i++){ if(s[i]=='0'){ int cnt = 0; if(i==0) v.push_back(0); for(j=i - 1;j>=0;j--){ if(j!=0 && s[j]=='1'){ cnt++; }else{ v.push_back(cnt); break; } } } } int m = v.size(),sum = 300; dp[m][0][0] = 1; for(i=m - 1;i>=0;i--){ for(l=0;l<=sum;l++){ dp2[sum][l] = dp[i + 1][sum][l]; for(j=sum - 1;j>=0;j--){ dp2[j][l] = dp2[j + 1][l]; (dp2[j][l] += dp[i + 1][j][l]); } } for(j=0;j<=sum;j++){ for(l=0;l<=sum;l++){ (dp[i][j][l] += dp2[j][l]) %= mod; for(r=1;r<=min({j,l,v[i]});r++){ (dp[i][j][l] += dp[i + 1][j - r][l - r]) %= mod; } } } } ll ans = 0; for(i=0;i<=min(300,k);i++){ (ans += dp[0][0][i]) %= mod; } cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define int ll #define REP(i,n) for (int i = 0; i < (n); ++i) #define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++) #define ALL(vec) (vec).begin(), (vec).end() #define REVALL(vec) (vec).rbegin(), (vec).rend() #define debug(x) cerr << #x << ": " << x << '\n' #define hyphen() cerr << "--\n" #define fst first #define pb push_back const int MOD = (int)1e9 + 7; int bigger(int a, int b) { return a >= b ? a : b; } int smaller(int a, int b) { return a >= b ? b : a; } signed main() { int N; cin >> N; vector<int> As(N); vector<int> Bs(N); REP(i, N) { cin >> As.at(i) >> Bs.at(i); } // (priority, score, ind) vector<tuple<int, int, int>> sorted_for_a(N); vector<tuple<int, int, int>> sorted_for_b(N); REP(i, N) { int a = As.at(i); int b = Bs.at(i); int priority = a + b; tuple<int, int, int> ta = make_tuple(priority, a, i); tuple<int, int, int> tb = make_tuple(priority, b, i); sorted_for_a.pb(ta); sorted_for_b.pb(tb); } sort(REVALL(sorted_for_a)); sort(REVALL(sorted_for_b)); queue<tuple<int, int, int>> a_queue; for (auto a : sorted_for_a) { a_queue.push(a); } queue<tuple<int, int, int>> b_queue; for (auto b : sorted_for_b) { b_queue.push(b); } // それが食べられたことを表す配列 vector<bool> eaten(N, false); // ここから作業開始 int score_a = 0; int score_b = 0; tuple<int,int,int> ta; tuple<int,int,int> tb; while(!a_queue.empty() || !b_queue.empty()) { // Aのターン // 食べられていない料理が見つかるまで捨てる while(true) { if (a_queue.empty()) { break; } ta = a_queue.front(); a_queue.pop(); int& ind = get<2>(ta); if (!eaten.at(ind)) { break; } } if (a_queue.empty()) { break; } // Aが食べる処理 int& a = get<1>(ta); int& ind_a = get<2>(ta); debug(a); debug(ind_a); score_a += a; debug(ind_a); eaten.at(ind_a) = true; // 食べられていない料理が見つかるまで捨てる while(true) { if (b_queue.empty()) { break; } tb = b_queue.front(); b_queue.pop(); int& ind = get<2>(tb); if (!eaten.at(ind)) { break; } } // Bが食べる処理 // 後攻はもう食べるものが無い可能性がある if (b_queue.empty()) { break; } int& b = get<1>(tb); int& ind_b = get<2>(tb); debug(b); debug(ind_b); score_b += b; debug(ind_b); eaten.at(ind_b) = true; } cout << score_a - score_b << endl; }
#include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long #define all(v) (v).begin(), (v).end() #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<n;++i) #define FOR(i, m, n) for(int i = m; i < n; i++) #define EPS (1e-7) #define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vector<ll> > vvl; typedef vector<vector<vector<ll> > > vvvl; ll MOD = 1000000007; const long long L_INF = 1LL << 60; const int INF = 2147483647; // 2^31-1 const double PI = acos(-1); //cout<<fixed<<setprecision(10); template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;} template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;} template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;} const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; signed main() { gearup; int n;cin >> n; vl a(n),b(n),c(n); rep(i,n){ cin >> a[i] >> b[i]; c[i] = a[i] + b[i]; } sort(all(c),greater<ll>()); //降順そーと ll res = 0,res1=0; rep(i,n){ if(i%2==0)res+=c[i]; else res1+=c[i]; } cout << res - accumulate(all(b),0LL) << endl; }
1
#include <iostream> #include <algorithm> using namespace std; int main(){ int score[20]={}; for(int i=0;i<10;i++){ cin >> score[i]; } sort(score, score+10); int score2[20]={}; for(int i=0;i<10;i++){ cin >> score2[i]; } sort(score2,score2+10); int sum1=score[9]+score[8]+score[7]; int sum2=score2[9]+score2[8]+score2[7]; cout << sum1 << ' '<< sum2 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; } template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; } template<typename H> void read(H& head) { cin >> head; } template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); } template<typename H> void write(H head) { cout << head << '\n'; } template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); } template<typename ...T> void die(T ...tok) { write(tok...); exit(0); } int main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); int n, k; read(n, k); vector<int> v(n); rep(i, 0, n) read(v[i]); ll ans = 0; rep(i, 0, min(n, k) + 1) { int p = k - i; // put back rep(j, 0, i + 1) { int left = j, right = i - j; multiset<int> m; rep(k, 0, left) m.insert(v[k]); rep(k, 0, right) m.insert(v[n - 1 - k]); rep(k, 0, p) if (m.size() && *m.begin() < 0) m.erase(m.begin()); ll lans = 0; for (int h : m) lans += h; chmax(ans, lans); } } die(ans); }
0
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repc(i, n) for (int i = 0; i <= int(n); i++) #define rrepc(i, n) for (int i = int(n); i >= 0; i--) #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define repic(i, a, b) for (int i = int(a); i <= int(b); i++) #define all(a) (a).begin(), (a).end() #define bit32(x) (1 << (x)) #define bit64(x) (1ll << (x)) #define sz(v) ((int) v.size()) using namespace std; using i64 = long long; using f80 = long double; using vi32 = vector<int>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; void yes() { cout << "Yes" << endl; exit(0); } void no() { cout << "No" << endl; exit(0); } template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {}; template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {}; template <typename T> void amax(T &x, T y) { x = max(x, y); } template <typename T> void amin(T &x, T y) { x = min(x, y); } template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; } void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; } const int INF = 1001001001; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; void solve() { int n, k; cin >> n >> k; vi32 a(n); cin >> a; while (k--) { auto p = a; a.assign(n, 0); rep(i, n) { int l = max(0, i - p[i]); int r = min(n, i + p[i] + 1); a[l] += 1; if (r < n) a[r] -= 1; } rep(i, n - 1) a[i + 1] += a[i]; if (a == p) { break; } } cout << a << endl; }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <cmath> #include <deque> #include <unordered_map> #define IOS ios_base::sync_with_stdio(0); cin.tie(0) using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; const int MAXN = 234567; int A[MAXN]; int sum[MAXN]; int main() { int N, K; scanf("%d %d", &N, &K); for (int i = 0; i < N; i++) scanf("%d", &A[i]); while (K--) { for (int i = 0; i < N; i++) { int l = max(0, i - A[i]); int r = min(N, i + A[i]) + 1; sum[l]++; sum[r]--; } int cur = 0; for (int i = 0; i < N; i++) { cur += sum[i]; A[i] = cur; sum[i] = 0; } bool OK = false; for (int i = 0; i < N; i++) { if (A[i] != N) OK = true; } if (!OK) break; } for (int i = 0; i < N; i++) printf("%d ", A[i]); return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN by Benq; */
1
#include <iostream> #include <queue> #include <vector> #include <algorithm> using namespace std; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { int h, w; cin >> h >> w; vector<vector<bool>> tile(h + 2, vector<bool>(w + 2, false)); for(int i = 1; i <= h; ++i) { for(int j = 1; j <= w; ++j) { char ch; cin >> ch; if(ch == '.') tile[i][j] = true; } } bool isTrue = false; vector<vector<bool>> visited(h + 2, vector<bool>(w + 2, false)); struct node { vector<pair<int, int>> walked; int i, j; void AddWalked(int i, int j) { walked.emplace_back(make_pair(i, j)); } node(int i = 1, int j = 1) : walked(vector<pair<int, int>>()), i(i), j(j) {} }; queue<node> q; q.push(node(1, 1)); node ansNode; while(!q.empty()) { auto nowNode = q.front(); q.pop(); int ni = nowNode.i, nj = nowNode.j; if(!tile[ni][nj] || visited[ni][nj]) continue; visited[ni][nj] = true; if(ni == h && nj == w) { isTrue = true; ansNode = nowNode; break; } for(int i = 0; i < 4; ++i) { if(tile[dx[i] + ni][dy[i] + nj]) { node newNode(dx[i] + ni, dy[i] + nj); newNode.walked = nowNode.walked; newNode.AddWalked(dx[i] + ni, dy[i] + nj); q.push(newNode); } } } int answerCount = 0; if(isTrue) { tile[1][1] = false; for(int i = 0; i < ansNode.walked.size(); ++i) { int ai = ansNode.walked[i].first, aj = ansNode.walked[i].second; tile[ai][aj] = false; } for(int i = 1; i <= h; ++i) for(int j = 1; j <= w; ++j) if(tile[i][j]) answerCount++; } if(isTrue) cout << answerCount << endl; else cout << -1 << endl; }
#include <stdio.h> #include <cmath> #include <algorithm> #include <stack> using namespace std; struct Info{ Info(){ rank = cost = point = 0; } int cost,point,rank; }; int main(){ int num_sport,num_member,cost_limit,maximum,max_index; Info info[1000]; scanf("%d %d",&num_sport,&num_member); for(int i = 0; i < num_sport; i++){ scanf("%d",&info[i].cost); info[i].rank = i+1; } for(int i = 1; i <= num_sport-1; i++){ for(int k = num_sport-1; k >= i; k--){ if(info[k].cost < info[k-1].cost)swap(info[k],info[k-1]); } } for(int i = 0; i < num_member; i++){ scanf("%d",&cost_limit); maximum = 1000000000; for(int k = 0; k < num_sport; k++){ if(info[k].cost > cost_limit)break; if(info[k].rank < maximum){ maximum = info[k].rank; max_index = k; } } info[max_index].point++; } maximum = -1; for(int i = 0; i < num_sport; i++){ if(info[i].point > maximum){ maximum = info[i].point; max_index = i; } } printf("%d\n",info[max_index].rank); return 0; }
0
#include <bits/stdc++.h> #define pb push_back #define ll long long #define f first #define s second using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef debug freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif vector<int> vec; vec.pb(111); vec.pb(222); vec.pb(333); vec.pb(444); vec.pb(555); vec.pb(666); vec.pb(777); vec.pb(888); vec.pb(999); int n; cin >> n; int t = *lower_bound(vec.begin(), vec.end(), n); cout << t << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using P = pair<int,int>; int main() { string s; cin >> s; vector<bool> app(26); rep(i, s.size()) app[s[i] - 'a'] = true; rep(i, 26) if(!app[i]) { cout << string(1, i + 'a') << "\n"; return 0; } cout << "None" << "\n"; return 0; }
0
#include "bits/stdc++.h" using namespace std; long long dfs(long long K, long long A, long long B, long long C) { if (K == 0) { return A + B + C; } long long a = dfs(K - 1, 2 * A, B, C); long long b = dfs(K - 1, A, 2 * B, C); long long c = dfs(K - 1, A, B, 2 * C); return max(max(a, b), c); } void Main() { long long A, B, C; cin >> A >> B >> C; long long K; cin >> K; long long ans = dfs(K, A, B, C); cout << ans << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
#include<iostream> #include<string> #include<map> #include<algorithm> using namespace std; typedef long long ll; const int Max = 1e3 + 7; int ls1[Max], ls2[Max]; int n; int main() { int a, b; string str; cin >> a >> b; cin >> str; int f = 0; for (int i = 0; i <= str.size() - 1; i++) { if (i == a) { if (str[i] != '-') { f = 1; break; } } else { if (!(str[i] <= '9' && str[i] >= '0')) { f = 1; break; } } } if (f)cout << "No"; else cout << "Yes"; }
0
#include <bits/stdc++.h> #define fi first #define se second const int N = 1000100; using namespace std; int n; char a[N]; char b[N]; int last[N][26]; int main() { ios_base::sync_with_stdio(false); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; for(int j = 0; j < 26; j++){ last[i][j] = last[i - 1][j]; } last[i][a[i] - 'a'] = i; } bool good = true; for(int i = 1; i <= n; i++){ cin >> b[i]; if(a[i] != b[i]){ good = false; } } if(good){ cout << 0 << "\n"; return 0; } queue < int > v; int res = 0, gg = n; for(int i = n; i >= 1; i--){ if(gg > i){ gg = i; } if(a[gg] == b[i]){ continue; } int h = last[gg][b[i] - 'a']; if(h == 0){ cout << -1 << "\n"; return 0; } gg = h; while(!v.empty() && v.front() - v.size() >= i){ v.pop(); } v.push(h); res = max(res, (int)v.size()); } cout << res << "\n"; }
#include<bits/stdc++.h> using namespace std; const int N=1e6+5; char s[N],t[N]; int n,ans,l=1,r,last,q[N]; int main(){ scanf("%d%s%s",&n,s+1,t+1),last=n; for(int i=n;i;){ while(last&&(i<last||s[last]!=t[i])) --last; if(!last) {puts("-1");return 0;} while(l<=r&&q[l]-r+l-1>=i) ++l; q[++r]=last; if(i!=last) ans=max(ans,r-l+1); while(t[i]==s[last]&&i>=last) --i; } printf("%d\n",ans); return 0; }
1
/* * File: main.cpp * Author: freebsd * * Created on 2014/08/28, 10:07 */ #include <cstdio> using namespace std; int main() { while (true) { int n = 0; int ice[10] = {0}, icetemp = 0; scanf("%d", &n); if(n == 0) break; for (int i = 0; i < n; i++) { icetemp = 0; scanf("%d", &icetemp); ice[icetemp]++; } for (int i = 0; i < 10; i++) { if(ice[i] > 0) { for(int j = 0; j < ice[i]; j++){ printf("*"); } }else { printf("-"); } printf("\n"); } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int intl; typedef unsigned long long intu; #define int long long // change here #define sfi(x) scanf("%lld", &x) // change here #define sfi2(x, y) sfi(x) , sfi(y) #define sfi3(x, y, z) sfi(x) , sfi(y) , sfi(z) #define sfc(x) scanf(" %c", &x) #define sfs(x) scanf(" %s", x) #define sfsn(x) scanf(" %[^\n]s", x) #define pfi(x) printf("%lld", (intl)x) #define pfis(x) printf("%lld", (intl)x), printf(" ") #define pfin(x) printf("%lld", (intl)x), printf("\n") #define pfs(x) printf("%s", x) #define pfnl printf("\n") #define pfsp printf(" ") #define endl '\n' #define sp ' ' #define watch(x) cout<<"::debug:: "<< #x <<" : "<<x<<endl #define watchi(i, x) cout<<"::debug:: "<< #x <<"-> ["<<i<<"]"<<" : "<<x<<endl #define FOR(i, begin, end) for(__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define repit(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it) #define perit(it, x) for(__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); ++it) #define rep(i, begin, end) for(int i = (begin), ed = (end); i < (ed); ++i) #define per(i, end, begin) for(int i = (end)-1, bg = (begin); i >= (bg); --i) #define setvalue(a, v) for(int i = 0, sz = (sizeof(a)/sizeof(*a)); i<sz; i++){ a[i] = v; } #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define all(a) a.begin(), a.end() #define min3(x, y, z) min(x,min(y,z)) #define max3(x, y, z) max(x,max(y,z)) #define PI 2*acos(0) #define INF 1000000007 #define debug if( 1 ) const int mxn = 100010; void solve(int tc) { int n; cin >> n; int arr[2*n]; for(int i=0; i<2*n; i++) cin >> arr[i]; sort(arr, arr+2*n); int tot = 0; for(int i=0; i<2*n; i+=2) tot += arr[i]; cout << tot << endl; } int32_t main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(1); //int tc; cin>>tc; for(int t=1; t<=tc; t++) solve(t); return 0; }
0
#include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> namespace IO { template <typename _T> inline bool read (_T& x) { x = 0; _T y = 1; char c = getchar(); while ((c < '0' || '9' < c) && c != EOF) { if (c == '-') y = -1; c = getchar(); } if (c == EOF) return false; while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar(); x *= y; return true; } template <typename _T> inline _T input () { _T x = 0, y = 1; char c = getchar(); while ((c < '0' || '9' < c) && c != EOF) { if (c == '-') y = -1; c = getchar(); } if (c == EOF) return 0; while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar(); x *= y; return x; } }; using namespace IO; namespace modular { const int MOD = 1000000007; inline int add (int x, int y) { return (x += y) >= MOD ? x -= MOD : x; } inline void inc (int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; } inline int mul (int x, int y) { return 1LL * x * y % MOD; } inline int qpow (int x, int y) { int ans = 1; for (; y; y >>= 1, x = mul(x, x)) if (y & 1) ans = mul(ans, x); return ans; } }; using namespace modular; #define reg register #define MAX_N 200007 #define FIN(s) freopen(s, "r", stdin) #define FOUT(s) freopen(s, "w", stdout) #define debug(...) fprintf(stderr, __VA_ARGS__) #define rep(i, l, r) for(int i = l; i <= r; ++i) #define lep(i, l, r) for(int i = l; i < r; ++i) #define irep(i, r, l) for(int i = r; i >= l; --i) #define ilep(i, r, l) for(int i = r; i > l; --i) typedef long long ll; int N, M, A, B; int fac[MAX_N], ifac[MAX_N]; inline int C (int x, int y) { if (x < y || y < 0) return 0; return mul(fac[x], mul(ifac[y], ifac[x - y])); } inline void init () { int MX = 200000; fac[0] = ifac[0] = 1; rep (i, 1, MX) fac[i] = mul(fac[i - 1], i); ifac[MX] = qpow(fac[MX], MOD - 2); irep (i, MX, 2) ifac[i - 1] = mul(ifac[i], i); } int main () { #ifdef LOCAL FIN("in"); #endif init(); read(N), read(M), read(A), read(B); int res = 0; rep (i, 1, B) inc(res, mul(C(N - A - 1 + i - 1, i - 1), C(A - 1 + M - i, M - i))); res = add(C(N + M - 2, N - 1), MOD - res); printf("%d\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 int64_t expotent(int64_t n,int64_t m){ if (m == 1) return n; else if (m % 2 == 0) return expotent(n * n % MOD, m/2); else return expotent(n * n % MOD, m/2) * n % MOD; } int64_t nCr(int64_t n, int64_t r){ int Ans = 1; if (r > n / 2) r = n - r; for (int i = 1; i <= r; i++) Ans = Ans * (n + 1 - i) % MOD * expotent(i, MOD-2) %MOD; return Ans; } int main(){ int64_t H, W, A, B; int64_t currentways = 1; int64_t ways = 0; cin >> H >> W >> A >> B; currentways = nCr(H+W-B-2, W-B-1); ways += currentways; for (int i = 1; i < H-A; i++){ //ways += nCr(i+B-2, B-1) * nCr(H+W-i-B-1, W-B-1); currentways = currentways * (i+B-1) % MOD * expotent(i, MOD-2) % MOD * (H-i) % MOD * expotent(H+W-i-B-1, MOD-2) %MOD; ways =(ways + currentways) % MOD; } cout << ways; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define all(v) begin(v),end(v) using ll = long long; int main() { vector<string> s(3); vector<int> vec(3),cnt(3); int n=0; rep(i,3){ cin>>s[i]; n+=s[i].size(); cnt[i]=s[i].size(); } int x=0; rep(i,n){ if(cnt[x]==vec[x]){ cout<<(char)(x+'A')<<endl; return 0; } x=s[x][vec[x]++]-'a'; } }
#include <bits/stdc++.h> using namespace std; int main() { string SA, SB, SC; cin >> SA >> SB >> SC; int ind_A = 1, ind_B = 0, ind_C = 0; char cur = SA[0]; while(true) { // 文字を見る if (cur == 'a') { // 終了条件のチェック if (ind_A == SA.size()) { cout << "A" << endl; return 0; } else { // 終了しない場合の cur の更新 cur = SA[ind_A]; ind_A++; } } else if (cur == 'b') { // Bのカードを見る // 終了条件のチェック if (ind_B == SB.size()) { cout << "B" << endl; return 0; } else { // 終了しない場合の cur の更新 cur = SB[ind_B]; ind_B++; } } else { // 終了条件のチェック if (ind_C == SC.size()) { cout << "C" << endl; return 0; } else { // 終了しない場合の cur の更新 cur = SC[ind_C]; ind_C++; } } } }
1
#include <bits/stdc++.h> using namespace std; char a[6][6]={"aacd","bbcd","cdaa","cdbb"}; char b[8][8]={"aabba","bcc.a","b..cb","a..cb","abbaa"}; char c[8][8]={"bbacc.","a.a..c","abb..c","cc.bba","..ca.a","..cabb"}; char d[9][9]={"eeffee.","aa.aa.e","..a..ae","..a..af","aa.aa.f","..a..ae","..a..ae"}; char ans[1002][1002]; void f(int n,int k){ if(n==1)return; int i,j; char q='a'; char w='b'; if(k%2)q='c',w='d'; char c=q; for(i=1 ; i<n ; i+=2){ a[k][i-1+k]=a[k][i+k]=c; if(c==q)c=w; else c=q; } for(i=1 ; i<n ; i+=2){ a[i+k][n-1+k]=a[i-1+k][n-1+k]=c; if(c==q)c=w; else c=q; } for(i=n-1 ; i>=1 ; i-=2){ a[n-1+k][i+k]=a[n-1+k][i+k-1]=c; if(c==q)c=w; else c=q; } for(i=n-1 ; i>=1 ; i-=2){ a[i+k][k]=a[i-1+k][k]=c; if(c==q)c=w; else c=q; } f(n-2,k+1); } void check(int n){ int i,j; int s=0; for(i=0 ; i<n ; i++){ if(a[0][i]!='.' && a[0][i]!=a[0][i+1])s++; } for(i=0 ; i<n ; i++){ int cnt=0; for(j=0 ; j<n ; j++){ if(a[i][j]!='.' && a[i][j]!=a[i][j+1])cnt++; } if(cnt!=s)cout<<"!"; } for(i=0 ; i<n ; i++){ int cnt=0; for(j=0 ; j<n ; j++){ if(a[j][i]!='.' && a[j+1][i]!=a[j][i])cnt++; } if(cnt!=s)cout<<"!"; } } int main(){ cin.tie(0); int n; ios_base::sync_with_stdio(0); cin>>n; int i,j; int k=0; int m=n; if(n==2 ){ cout<<-1; return 0; } if(n==7){ for(i=0 ; i<7 ; i++)cout<<d[i]<<endl; return 0; } if(n==3){ cout<<"aa."<<endl<<"..a"<<endl<<"..a"; return 0; } while(n){ if(n==11){ n-=5; for(i=0 ; i<5 ; i++){ for(j=0 ; j<5 ; j++){ ans[n+i][n+j]=b[i][j]; } } n-=6; for(i=0 ; i<6 ; i++){ for(j=0 ; j<6 ; j++) ans[i][j]=c[i][j]; } break; } if(n==5){ n-=5; for(i=0 ; i<5 ; i++){ for(j=0 ; j<5 ; j++){ ans[i][j]=b[i][j]; } } break; } if(n==6){ n-=6; for(i=0 ; i<6 ; i++){ for(j=0 ; j<6 ; j++) ans[i][j]=c[i][j]; } break; } n-=4; for(i=0 ; i<4 ; i++){ for(j=0 ; j<4 ; j++){ ans[n+i][n+j]=a[i][j]; } } } for(i=0 ; i<m ; i++){ for(j=0 ; j<m ; j++){ if(ans[i][j]==0)cout<<'.'; else cout<<ans[i][j]; } cout<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } typedef long long int ll; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define endl "\n" const double EPS = 1e-7; const int INF = 1 << 30; const ll LLINF = 1LL << 60; const double PI = acos(-1); const int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- vector<string> three = { "add", "a.c", "bbc", }; vector<string> four = { "afgg", "afhh", "bbde", "ccde", }; vector<string> five = { "ahhii", "ag..j", "bg..j", "b.ffe", "ccdde", }; vector<string> six = { "aa.bbc", "de...c", "deff..", "..gghi", "j...hi", "jkk.ll", }; vector<string> seven = { "a.jj.kk", "ai..ll.", ".i.mm.o", "b.h...o", "b.h..g.", ".ff..ge", "cc.dd.e", }; int n; // 4,5,6,7 void solve(int a, int b, int c, int d) { vector<string> ans(n, string(n, '.')); int id = 0; for(int i = 0; i < a; i++) { for(int y = id; y < id + 4; y++) { for(int x = id; x < id + 4; x++) { ans[y][x] = four[y - id][x - id]; } } id += 4; } for(int i = 0; i < b; i++) { for(int y = id; y < id + 5; y++) { for(int x = id; x < id + 5; x++) { ans[y][x] = five[y - id][x - id]; } } id += 5; } for(int i = 0; i < c; i++) { for(int y = id; y < id + 6; y++) { for(int x = id; x < id + 6; x++) { ans[y][x] = six[y - id][x - id]; } } id += 6; } for(int i = 0; i < d; i++) { for(int y = id; y < id + 7; y++) { for(int x = id; x < id + 7; x++) { ans[y][x] = seven[y - id][x - id]; } } id += 7; } for(int i = 0; i < n; i++) { cout << ans[i] << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; if(n <= 2) { cout << -1 << endl; return 0; } if(n == 3) { for(int i = 0; i < three.size(); i++) { cout << three[i] << endl; } return 0; } for(int i = 0; i * 7 <= n; i++) { for(int j = 0; j * 6 <= n; j++) { for(int k = 0; k * 5 <= n; k++) { int sum = i * 7 + j * 6 + k * 5; if(sum <= n && (n - sum) % 4 == 0) { int l = (n - sum) / 4; solve(l, k, j, i); return 0; } } } } cout << -1 << endl; }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; const int MOD=1000000007; const int INF= int(1e9); const int MAX =1007; string a,b; int n,m; int dp[MAX][MAX]; int solve ( int n,int m) { if(dp[n][m] != -1) { return dp[n][m]; } else if(m == 0) { return dp[n][m]=n; } else if(n == 0) { return dp[n][m]=m; } if (a[n-1] == b[m-1] ) { return dp[n][m]=solve(n-1,m-1); } dp[n][m] = 1 + min( solve(n-1,m-1) , min ( solve(n-1,m) ,solve(n,m-1) ) ); return dp[n][m]; } int main() { ios_base::sync_with_stdio(false); for(int i=0;i<MAX;i++) { for(int j=0;j<MAX;j++) { dp[i][j]=-1; } } cin>>a; cin>>b; n=a.size(),m=b.size(); solve(n,m); cout<<dp[n][m]<<"\n"; return 0; }
#include <iostream> #include <string> #define int long long //#define _DEBUG using namespace std; string sa, sb; int T[1009][1009]; int solve(){ int sal = sa.length(), sbl = sb.length(); for(int a=0; a<=sal; a++){ for(int b=0; b<=sbl; b++){ if(a==0){ T[a][b] = b; }else if(b==0){ T[a][b] = a; }else{ T[a][b] = min(min(T[a][b-1]+1, T[a-1][b]+1), T[a-1][b-1]+((sa[a-1]==sb[b-1])?0:1)); } } } return T[sal][sbl]; } signed main(){ while(cin >> sa >> sb){ cout << solve() << endl; } }
1
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define watch(x) cout<<(#x)<<"="<<(x)<<'\n' #define mset(d,val) memset(d,val,sizeof(d)) #define setp(x) cout<<fixed<<setprecision(x) #define forn(i,a,b) for(int i=(a);i<(b);i++) #define fore(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define F first #define S second #define pqueue priority_queue #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; void amin(ll &a, ll b){ a=min(a,b); } void amax(ll &a, ll b){ a=max(a,b); } void SD(int t=0){ cout<<"PASSED "<<t<<endl; } const ll INF = ll(1e18); const int MOD = 1e9+7; ll add(ll a,ll b) { a%=MOD; b%=MOD; a+=b;a%=MOD; if(a<0) a+=MOD; return a; } ll mult(ll a, ll b) { a%=MOD; b%=MOD; ll ans=(a*b)%MOD; if(ans<0) ans+=MOD; return ans; } ll pw(ll a, ll b) { ll r=1; while(b){ if(b&1) r=mult(r,a); a=mult(a,a); b>>=1; } return r; } ll inverse(ll a) { return pw(a,MOD-2); } const int MAXN = 100005; void NO(){ cout<<0<<'\n'; exit(0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; int a[n]; forn(i,0,n) cin>>a[i]; int c[3]{}; ll ans=1; forn(i,0,n){ int cnt=0; forn(j,0,3){ if(a[i]==c[j]) cnt++; } ans=mult(ans,cnt); forn(j,0,3){ if(a[i]==c[j]){ c[j]++; break; } } } cout<<ans<<'\n'; return 0; }
/* ID: anonymo14 TASK: wormhole LANG: C++ */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<pair<int,int>> vpii; #define F first #define S second #define PU push #define PUF push_front #define PUB push_back #define PO pop #define POF pop_front #define POB pop_back #define REP(i,a,b) for(int i=a; i<=b; i++) #define MOD 1000000007 void solve(int test_case) {//236 double n; cin>>n; double mi = LONG_MAX; REP(i,1,5){ double val; cin>>val; mi=min(mi,val); } if(n<=mi)cout<<5; else printf("%lld",(ll)ceil(n/mi)+4); } int main() { ////// FILE BASED IO//// //freopen("wormhole.in", "r", stdin); //freopen("wormhole.out", "w", stdout); /////////////// ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; REP(i,1,t) { solve(i); } return 0; }
0
#include<iostream> #include<algorithm> using namespace std; typedef long long ll; const int N = 200010; int n, a[N], b[N], cnt, tot; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[n - i + 1]; int l = 1, r = n, st = 0, ed = -1; for (int i = 1; i <= n; i++) if (a[i] == b[i]) { if (!st) st = i; ed = i; } for (int j = st; j <= ed; j++) { if (a[l] ^ b[j] && b[l] ^ b[j]) swap(b[j], b[l++]); else if (a[r] ^ b[j] && b[r] ^ b[j]) swap(b[j], b[r--]); else puts("No"), exit(0); } puts("Yes"); for (int i = 1; i <= n; i++) printf("%d%c", b[i], " \n"[i == n]); return 0; }
#include <iostream> #include <string.h> #include <sstream> #include <ctype.h> using namespace std; string com[3] = {"the", "this", "that"}; string incAlpha (string str, int k) { for (int i = 0; i < str.size(); i++) { if(isalpha(str[i])) str[i] = ((str[i] + k - 'a') % 26) + 'a'; } return str; } bool strsrch(string str1, string str2) { for (int i = 0; i < str1.size(); i++) { if (str1[i] == str2[0]) { bool flag = true; if (i + str2.size() > str1.size()) flag = false; for (int j = 0; j < str2.size() && flag; j++) { if (str1[i + j] != str2[j]) flag = false; } if (flag) return true; } } return false; } bool check (string str) { for (int i = 0; i < 3; i++) { if (strsrch(str, com[i])) return true; } return false; } int main () { string str; while (getline(cin, str)) { for (int i = 0; i <= 26; i++) { if (check((incAlpha(str, i)))) { cout << (incAlpha(str, i)) << endl; break; } } } return 0; }
0
#include<bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (int)(n); i++) #define put(i) cout<<fixed<<i<<endl using namespace std; using ll = long long; int main(){ ll n; cin >> n; map<ll,ll> mp; rep(i,n){ ll tmp; cin >> tmp; mp[tmp]++; } ll m1 = 0, m2 = 0; for(auto x:mp){ if(x.second > 1 && (x.first > m1 || x.first > m2)){ if(m1 < m2){ m1 = x.first; }else{ m2 = x.first; } } if(x.second > 3){ if(x.first > m1){ m1 = x.first; } if(x.first > m2){ m2 = x.first; } } } put(m1 * m2); }
#include <iostream> int main(void){ int N, tmp=200001, ans=0; std::cin >> N; for (int i=0; i<N; ++i){ int a; std::cin >> a; if (a < tmp){ ++ans; tmp = a; } } std::cout << ans << std::endl; return 0; }
0
#include <iostream> #include <iomanip> #include <vector> #include <map> #include <algorithm> #include <string> #include <numeric> #include <math.h> using namespace std; void func() { int N; cin >> N; int64_t sum = 0; int64_t a; cin >> a; for (int i = 1; i < N; ++i) { int64_t tmp; cin >> tmp; if (tmp < a) { sum += (a - tmp); tmp += (a - tmp); } a = tmp; } cout << sum << endl; } int main() { // while(1) func(); return 0; }
#include <bits/stdc++.h> using namespace std; #define print cout << #define printl(s) cout << s << endl; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; const ll modseed = pow(10,9) + 7; template <typename T> vector<T> getValues(int num){ vector<T> values(num); for(int i=0;i<num;i++){ cin >> values.at(i); } return values; } ll calculateMod(ll n, ll expo, ll modSeed){ ll ret = 1; rep(i, expo){ ret *= n; ret = ret%modSeed; } return ret; } int main(){ ll N; cin >> N; auto inputs = getValues<ll>(N); vector<ll> steps(N,0); ll ans = 0; rep(i, N){ if(i==0){ continue; } ll maenohito = steps.at(i-1) + inputs.at(i-1); ll sub = inputs.at(i) - maenohito; if(sub < 0){ steps.at(i) = -sub; ans += steps.at(i); } } printl(ans); }
1
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N, X, T; cin >> N >> X >> T; int q = (N / X) + (N % X != 0); cout << q*T; return 0; }
#include <bits/stdc++.h> #define ll long long #define endl "\n" using namespace std; void Fast() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); } inline int D() { int t; scanf("%d",&t); return t; } inline ll llD() { ll t; scanf("%lld",&t); return t; } const int Max=1e5+8; const int OO=-1e6; int xt[4]= {1,0,0,-1}; int yt[4]= {0,1,-1,0}; ll n,m,f,l; bool valid(int x,int y) { return x>-1 && y>-1 && x<n && y<m; } int mem[209][209][209],k; string st,st2; void init() { memset(mem,-1,sizeof mem); } ///////////////////////////////////////////////////////////////////// int solve (int i=0,int t=0,int j=n ) { } int main() { int T=1; ///T=D(); while(T-->0) { n=D(); int x=D(); int t= D(); int ans= (n/x)*t; if(n%x)ans+=t; cout<<ans; } }
1
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, k; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; int cur = 1; while (n) { cur = min(cur * 2, cur + k); --n; } cout << cur << endl; return 0; }
#include<iostream> using namespace std; int main() { int N, K; cin >> N >> K; int ans = 1000; for (int i = 0; i <= N; i++) { int num = 1; for (int k = 0; k < i; k++) { num *= 2; } for (int k = 0; k < N - i; k++) { num += K; } ans = min(ans, num); } cout << ans << endl; }
1
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") #define rep(i,n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) #define all(a) a.begin(),a.end() #define eb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define ub(v,k) (upper_bound(all(v),k)-v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> using ll=long long; using P=pair<ll,ll>; using PP=tuple<ll,ll,ll>; using S=multiset<ll>; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; const ll inf=1001001001001001; const int INF=1001001001; const int mod=1000000007; const double eps=1e-10; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void YesNo(T b){if(b)out("Yes");else out("No");} void decimal(int x){cout<<fixed<<setprecision(x);} ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);} ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);} ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;} vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;} void solve(){ ll n; cin>>n; vi a(n),b(n); rep(i,n) cin>>a[i]; rep(i,n) cin>>b[i]; //Yes or No vi c(200001,0),d(200001,0); rep(i,n) c[a[i]]++; rep(i,n) d[b[i]]++; bool f=true; rep(i,200001) if(c[i]+d[i]>n) f=false; YesNo(f); ll p=0; vi ans(n); //show example if(f){ REP(i,1,200001){ c[i]+=c[i-1]; d[i]+=d[i-1]; } REP(i,1,200001) chmax(p,c[i]-d[i-1]); rep(i,n) ans[(i+p)%n]=b[i]; outv(ans); } } signed main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include<iostream> #include<algorithm> #include<math.h> #include<queue> #include<vector> #include<climits> #include<map> #include<string> #include<functional> #include<iomanip> #include<deque> #include<random> #include<set> #include<bitset> #include<cassert> using namespace std; typedef long long ll; typedef double lldo; #define mp make_pair #define pub push_back #define rep(i,n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define chmax(x,y) x = max(x,y) ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else return gcd(b, a % b); } ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; } template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); } template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); } ll n, a[200005] = {}, b[200005] = {}, j = 0, bef = -1; int main() { cin >> n; rep(i, n)cin >> a[i]; rep(i, n)cin >> b[i]; rep(i, n) { if (bef != a[i])j = 0; if (a[i] == b[i]) { while ((a[i] == a[j] || a[i] == b[j]) && j < n)j++; if (j < n) { swap(b[i], b[j]); } else { cout << "No" << endl; return 0; } } bef = a[i]; } cout << "Yes" << endl; rep(i, n)cout << b[i] << endl; return 0; }
1
#include<bits/stdc++.h> using namespace std; ///Welcome to Nasif's Code #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; #define all(q) (q).begin(),(q).end() typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)1e9+7; const int MAX = 1e6; #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int main() { FastRead //freopen("output.txt", "w", stdout); ll n,m,sum=0,ans=0,a; cin>>n>>m; map<ll,ll>mp; mp[0]=1; while(n--) { cin>>a; sum+=a; sum%=m; ans+=mp[sum]++; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a) #define loop(i, s, n) loop2(i, s, n, 1) #define rep(i, n) loop(i, 0, n) #define pb push_back #define all(in) in.begin(),in.end() using ll = long long; using ull = unsigned long long; using namespace std; int main(){ int h, w; cin >> h >> w; int data[h][w]; rep(i,h) rep(j,w) cin >> data[i][j]; vector<vector<int>> ans(4,vector<int>()); rep(i,h) rep(j,w){ if(j == w-1){ if(i == h-1) continue; if(data[i][j]%2 == 1){ data[i][j]--; data[i+1][j]++; ans[0].push_back(i+1); ans[1].push_back(j+1); ans[2].push_back(i+2); ans[3].push_back(j+1); } } else if(data[i][j]%2 == 1){ data[i][j]--; data[i][j+1]++; ans[0].push_back(i+1); ans[1].push_back(j+1); ans[2].push_back(i+1); ans[3].push_back(j+2); } } cout << ans[0].size() << endl; rep(i,ans[0].size()) cout << ans[0][i] << " " << ans[1][i] << " " << ans[2][i] << " " << ans[3][i] <<endl; }
0
#include <iostream> using namespace std; int main(void){ int a,b,c,d; int ans=0; cin >> a >> b >> c >> d; if(a>b) ans +=b; else ans += a; if(c>d) ans +=d; else ans += c; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; ifstream fi("JJOOII.INP"); ofstream fo("JJOOII.OUT"); #define fi cin #define fo cout string S; int demJ,demO,demI,res; void xuli() { int i=0; while (1) { while (S[i]=='J') ++i,++demJ; while (S[i]=='O') ++i,++demO; while (S[i]=='I') ++i,++demI; if (demJ>=demO && demI>=demO) res=max(res,demO); demJ=demO=demI=0; if (S[i]=='@') return; } } int main() { fi>>S; S+='@'; xuli(); fo<<res<<'\n'; }
0
#include <cstdio> #include <cstdlib> #include <cstring> using namespace std; char h[3]={" \n"}; int main() { int w[3],x; for(int j=0;j<2;j++){ memset(w,0,sizeof(w)); for(int i=0;i<10;i++){ scanf("%d",&x); if(x>w[0]){w[2]=w[1]; w[1]=w[0]; w[0]=x;} else if(x>w[1]) {w[2]=w[1]; w[1]=x;} else if(x>w[2]) w[2]=x; } printf("%d%c",w[0]+w[1]+w[2],h[j]); } }
#include<stdio.h> #define INF 100000 int min(int a,int b){return a<b?a:b;} int getk(int a){ int res=0; while(a>0){ res++; a/=10; } return res; } int pow(int a,int b){ int l; int rt=1; for(l=0;l<b;l++)rt*=10; return rt; } int card[10]; int pos[10000]; int cpos; int main(){ int i,j; int n,k; while(1){ scanf("%d",&n); scanf("%d",&k); if(n==0&&k==0)return 0; for(i=0;i<n;i++)scanf("%d",&card[i]); cpos=0; int max=1; int ket; int next; int ni; int num; int ans=0; bool used[10]; for(i=0;i<k;i++)max*=n; for(i=0;i<max;i++){ cont: for(j=0;j<n;j++)used[j]=false; ket=1; ni=i; num=0; for(j=0;j<k;j++){ next=ni%n; ni/=n; if(used[next]){ i++; if(i==max)goto end; goto cont; } else used[next]=true; num+=card[next]*ket; ket*=pow(10,getk(card[next])); } for(j=0;j<cpos;j++){ if(num==pos[j])break; } if(j==cpos){ pos[cpos++]=num; ans++; } } end: printf("%d\n",ans); } }
0
#include <iostream> #include <set> #include <vector> using namespace std; int main() { string str; cin >> str; set<char> st; for(int i=0; i<str.size(); i++) { st.insert(str[i]); } if(st.size()<26) { cout << str; for(int i=0; i<26; i++) { if(st.find((char)('a'+i))==st.end()) { cout << (char)('a'+i) << endl; break; } } } else { set<char> vec; vec.insert(str[25]); int i; for(i=25; i>=1; i--) { if(str[i-1]<str[i]) { break; } vec.insert(str[i-1]); } if(vec.size()==26) { cout << -1 << endl; } else if(vec.upper_bound(str[i-1])!=vec.end()) { for(int j=0; j<i-1; j++) { cout << str[j]; } cout << (*vec.upper_bound(str[i-1])) << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; bool p = S.at(0) == 'R'; bool q = S.at(1) == 'R'; bool r = S.at(2) == 'R'; if(p && q && r) cout << 3 << endl; else if((p && q) || (q && r)) cout << 2 << endl; else if(p || q || r) cout << 1 << endl; else cout << 0 << endl; }
0
#include <cstring> #include <iostream> using namespace std; #define MAX_N 512 #define MAX_M 10240 int N, M, A[MAX_M], B[MAX_M]; bool LIST[2][MAX_N]; int main() { while (true) { memset(LIST, false, sizeof(LIST)); cin >> N >> M; if (N == 0 && M == 0) { break; } for (int i = 1; i <= M; i++) { cin >> A[i] >> B[i]; if (A[i] == 1) { LIST[0][B[i]] = true; LIST[1][B[i]] = true; } } for (int i = 1; i <= M; i++) { if (LIST[0][A[i]] == true) { LIST[1][B[i]] = true; } if (LIST[0][B[i]] == true) { LIST[1][A[i]] = true; } } int count = 0; for (int i = 2; i <= N; i++) { if (LIST[1][i] == true) { count++; } } cout << count << endl; } return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,k; while(cin >> n >> k){ if(!n && !k) break; int card[n]; rep(i,n) cin >> card[i]; sort( card, card + n ); int ans = 0; map<int,int> memo; do{ int temp = 0; rep(i,k){ temp *= 10; if(card[i]>9) temp *= 10; temp += card[i]; } if(memo[temp] == 0) ans++; memo[temp] = 1; }while(next_permutation( card, card + n )); cout << ans << endl; } return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll =long long; typedef vector<int> VI; typedef vector<VI> VVI; typedef pair<int,int> PII; #define SORT(a) sort((a).begin(),(a).end()) #define rSORT(a) reverse((a).begin(),(a).end()) #define For(i, a, b) for(int i = (a) ; i < (b) ; ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } using P = pair<int,int>; //Write From this Line bool isPrime(int x) { for(int i = 2; i * i <= x; i++){ if(x % i == 0) { return false; } } return true; } int main() { int n; cin >> n; for(int i = 2; i <= 55555; i++){ if(i%5 != 1) continue; if(isPrime(i)){ cout << i << endl; n--; } if(n == 0) break; } }
#include <bits/stdc++.h> using namespace std; #define FOR(i,o,n) for(long long i = o;i<n;i++) #define oneforall ios::sync_with_stdio(false);cin.tie(0); #define all(v) (v).begin(),(v).end() #define ini(...) int __VA_ARGS__; in(__VA_ARGS__) #define inl(...) long long __VA_ARGS__; in(__VA_ARGS__) #define ins(...) string __VA_ARGS__; in(__VA_ARGS__) #define int long long const long long inf=1e18; void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);} void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);} typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long > > vpll; typedef vector<pair<int, int > > vpii; #define FORR(x,arr) for(auto& x:arr) #define ZERO(a) memset(a,0,sizeof(a)) //3111111111111111111111111111111 bool isprime(int x){ for(int i = 2;i*i<=x;i++){ if(x%i == 0)return false; } return x!=1; } void solve(){ ini(n); vi morty; int i = 1; while(morty.size()!=55){ i++; int tmp = i*5+1; while(!isprime(tmp)){ i++; tmp = i*5+1; } morty.push_back(tmp); } FOR(i,0,n){ cout<<morty[i]<<" "; } out(); } int32_t main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall solve(); return 0; }
1
#include <iostream> #include <math.h> using namespace std; int main(){ int x, M; cin >> x; M = pow(x, 3.0); cout << M << endl; return 0; }
#include <iostream> int main() { int x; std::cin >> x; std::cout << x * x * x << "\n"; }
1
#define NODE 0 #define WEIGHT 1 #define COST_IDX 0 #define TIME_IDX 1 #define P_IDX 0 #define Q_IDX 1 #define R_IDX 2 #include <iostream> #include <cstring> using namespace std; int n, m, k; int weights[101][101][2]; int min_w[101][101][2]; int requests[200][3]; struct heap_queue { int arr[101]; int *cmp_val; int lookup[101]; int size=0; }; void heap_push(int elm, heap_queue &q) { q.arr[q.size] = elm; int above, i = q.size++; while (i && q.cmp_val[q.arr[(above=(i-1)>>1)]] > q.cmp_val[elm]) { q.arr[i] = q.arr[above]; q.lookup[q.arr[i]] = i; i = above; } q.arr[i] = elm; q.lookup[elm] = i; } int heap_pop(heap_queue &q) { int popped = q.arr[0]; int elm = q.arr[--q.size]; int below, i = 0; while ((below=(i<<1)+1) < q.size) { if (below+1 < q.size && q.cmp_val[q.arr[below+1]] < q.cmp_val[q.arr[below]]) below++; if (q.cmp_val[q.arr[below]] >= q.cmp_val[elm]) break; q.arr[i] = q.arr[below]; q.lookup[q.arr[i]] = i; i = below; } q.arr[i] = elm; q.lookup[elm] = i; return popped; } void change_val(int elm, heap_queue &q) { int above, i = q.lookup[elm]; while (i && q.cmp_val[q.arr[(above=(i-1)>>1)]] > q.cmp_val[elm]) { q.arr[i] = q.arr[above]; q.lookup[q.arr[i]] = i; i = above; } q.arr[i] = elm; q.lookup[elm] = i; } bool read_input() { cin >> n >> m; if (n*m == 0) return false; memset(weights, 0, sizeof(int)*101*101*2); memset(min_w, 0, sizeof(int)*101*101*2); for (int i = 0; i < n; i++) { int a, b, c, t; cin >> a >> b >> c >> t; weights[a][b][COST_IDX] = weights[b][a][COST_IDX] = c; weights[a][b][TIME_IDX] = weights[b][a][TIME_IDX] = t; } cin >> k; for (int i = 0; i < k; i++) { cin >> requests[i][P_IDX] >> requests[i][Q_IDX] >> requests[i][R_IDX]; } return true; } int resolve_request(int i_th) { int p, q, r; p = requests[i_th][P_IDX]; q = requests[i_th][Q_IDX]; r = requests[i_th][R_IDX]; if (min_w[p][q][r]) return min_w[p][q][r]; int weight_sum_map[101]; memset(weight_sum_map, -1, sizeof(int)*101); /* starting node has weight_sum of 0 */ weight_sum_map[p] = 0; int in_queue[101] = {}; heap_queue heap_q; heap_q.cmp_val = weight_sum_map; heap_push(p, heap_q); in_queue[p] = 1; while (heap_q.size) { int current_node = heap_pop(heap_q); in_queue[current_node] = 0; int weight_sum = weight_sum_map[current_node]; min_w[p][current_node][r] = weight_sum; if (current_node == q) break; for (int i = 1; i < 101; i++) { if (!weights[current_node][i][r]) continue; int adj_node = i; int w = weights[current_node][adj_node][r]; int new_weight_sum = weight_sum + w; if (weight_sum_map[adj_node] == -1 || new_weight_sum < weight_sum_map[adj_node]) { weight_sum_map[adj_node] = new_weight_sum; if (!in_queue[adj_node]) { heap_push(adj_node, heap_q); in_queue[adj_node] = 1; } else { change_val(adj_node, heap_q); } } } } return weight_sum_map[q]; } void solve() { //cout << endl; for (int i = 0; i < k; i++) cout << resolve_request(i) << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); while(read_input()) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std ; #define pb(n) push_back(n) #define fi first #define se second #define all(r) (r).begin(),(r).end() #define gsort(st,en) sort((st),(en),greater<int>()) #define vmax(ary) *max_element(all(ary)) #define vmin(ary) *min_element(all(ary)) #define debug(x) cout<<#x<<": "<<x<<endl #define fcout(n) cout<<fixed<<setprecision((n)) #define scout(n) cout<<setw(n) #define vary(type,name,size,init) vector< type> name(size,init) #define rep(i,n) for(int i = 0; i < (int)(n);++i) #define REP(i,a,b) for(int i = (a);i < (int)(b);++i) #define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it) #define repa(n,array) for(auto &n :(array)) using ll = long long; using vi = vector<int>; using vl = vector<ll>; using dict = map<string,int>; using pii = pair<int,int> ; const int mod = 1000000007; constexpr int imax = ((1<<30)-1)*2+1 ; constexpr int inf = 100000000; constexpr double PI = acos(-1.0) ; double eps = 1e-10 ; const int dy[] = {-1,0,1,0}; const int dx[] = {0,-1,0,1}; inline bool value(int x,int y,int w,int h){ return (x >= 0 && x < w && y >= 0 && y < h); } ll N,m; vector<vector<ll>> warshall_floyd(vector<vector<ll>> d){ rep(k,m){ rep(i,m){ rep(j,m){ d[i][j] = min(d[i][j],d[i][k] + d[k][j]); } } } return d; } int main(){ cin.tie(0); ios::sync_with_stdio(false); while(cin>>N>>m&&N&&m){ int a,b,c,d; vector<vector<ll>> time(m+1,vector<ll>(m+1,inf)); vector<vector<ll>> cost(m+1,vector<ll>(m+1,inf)); ++m; rep(i,N){ cin >> a >> b >> c >> d; time[a][b] = d; cost[a][b] = c; time[b][a] = d; cost[b][a] = c; } int k,p,q,r ; auto T = warshall_floyd(time); auto C = warshall_floyd(cost); cin >> k; rep(i,k){ cin >> p >> q >> r; if(r){ cout << T[p][q]<<endl; } else{ cout << C[p][q]<<endl; } } } return 0; }
1
#include<iostream> #include<vector> #include<algorithm> #include<string> #include<queue> #include<cmath> #include<cstdio> #include<tuple> #include<bitset> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;++i) #define rep1(i,n) for(int i=1;i<=n;++i) #define ALL(x) x.begin(),x.end() #define ll long long const int inf=1000000007; const int MOD=1000000007; int n,m; struct Map{ vector<vector<int>> map; void mkmap(vector<int> const& a,vector<int> const& b,vector<int>& num){ //num.resize(n*m+1,0); rep(i,n){ map.push_back(vector<int> (m,inf)); } rep(i,n){ rep(j,m){ map[i][j]=min(a[i],b[j]); if(a[i]==b[j])map[i][j]=999; } } } void show_map(){ rep(i,n){ rep(j,m){ cout<<map[i][j]<<" "; } cout<<endl; } } }; signed main(){ cin>>n>>m; vector<int> a(n); vector<int> b(m); vector<int> sum; vector<int> memo(n*m+1,0); vector<int> num(n*m+1,0); vector<int> list; rep(i,n)cin>>a[i]; rep(i,m)cin>>b[i]; //Map grid; //grid.mkmap(a,b,num); rep(i,n){ rep(j,m){ if(a[i]==b[j]){ sum.push_back(inf); ++num[a[i]]; list.push_back(a[i]); } else{ sum.push_back(min(a[i],b[j])); } } } sort(ALL(sum)); rep1(i,n*m){ memo[i]=memo[i-1]; if(num[i]==1)++memo[i]; else if(num[i]>1){ cout<<0<<endl; return 0; } } int cur=1; int res=1; sum.push_back(inf); sum.push_back(inf); int last=sum[0]; rep1(i,n*m){ if(last==sum[i]){ cur++; continue; } else{ if(num[last]==1){ rep1(k,cur){ res*=last-1-memo[last]-i+k+1; res%=MOD; } } else{ res*=cur; rep1(k,cur-1){ res*=last-1-memo[last]-i+k+1; res%=MOD; } } cur=1; } //cout<<sum[i]-memo[sum[i]]-i<<endl; if(res<0)res=0; res%=MOD; last=sum[i]; if(sum[i]==inf){ break; } } cout<<res<<endl; //grid.show_map(); /*rep(i,list.size()){ cout<<list[i]<<endl; }*/ //cout<<memo[182]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 typedef long long ll; #define rep(i,n) for(int i = 0;i < (n); i++) typedef pair<int, int> P; int main(){ int h,w; cin >> h >> w; int a[h][w]; vector<P>orig; vector<P>after; rep(i,h){ rep(j,w){ int temp; cin >> temp; a[i][j] = temp; } } int count = 0; rep(i,h-1){ rep(j,w){ if(a[i][j] % 2 != 0){ a[i][j]--; a[i+1][j]++; count++; P hoge; hoge.first = i+1; hoge.second = j+1; orig.push_back(hoge); hoge.first = i+2; after.push_back(hoge); } } } rep(i,w-1){ if(a[h-1][i] % 2 != 0){ a[h-1][i]--; a[h-1][i+1]++; count++; P hoge; hoge.first = h; hoge.second = i+1; orig.push_back(hoge); hoge.second = i+2; after.push_back(hoge); } } cout << count << endl; rep(i,count){ cout << orig[i].first << ' ' << orig[i].second << ' ' << after[i].first << ' ' << after[i].second << endl; } }
0
#include <bits/stdc++.h> using namespace std; using edge = pair<int, long long>; using Graph = vector<vector<edge>>; template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;} template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;} const long long INF = 1e12; vector<long long> dijkstra(const Graph &G, int s){ using Pi = pair<long long, int>; // 最終的に最短経路を保持する配列, INFで初期化 vector<long long> dist(G.size(), INF); // そこまでの距離, 頂点を保持する優先度付きキュー priority_queue<Pi, vector<Pi>, greater<Pi>> que; dist[s] = 0; que.emplace(dist[s], s); // キューが空になるまで(max V 回) while(!que.empty()){ long long sum_dist; int node; // キューから取り出された時点で頂点が確定 tie(sum_dist, node) = que.top(); que.pop(); // それより短い経路が分かっているときはcontinue(枝刈り) if (dist[node] < sum_dist) continue; // 確定した頂点から到達できる頂点を探索 for (auto &e : G[node]) { int next_node; long long dis; tie(next_node, dis) = e; // 最短距離が更新されたときだけキューに追加 if (chmin(dist[next_node], dist[node] + dis)) { que.emplace(dist[next_node], next_node); } } } return dist; } int main(){ int N, K, Case; Graph G; vector<vector<long long>> dist; while(true){ cin >> N >> K; if(N == 0 && K == 0)break; G.assign(N, vector<edge>()); dist.assign(N, vector<long long>(N, INF)); for (int i = 0; i < K; i++) { cin >> Case; if (Case == 0) { int s, g; cin >> s >> g; s--; g--; dist[s] = dijkstra(G, s); long long ans = dist[s][g]; if (ans == INF) ans = -1; cout << ans << endl; } else { int a, b; long long c; cin >> a >> b >> c; a--; b--; G[a].push_back(make_pair(b, c)); G[b].push_back(make_pair(a, c)); } } } return 0; }
#include<iostream> #include<algorithm> using namespace std; int *p,*rank; int V,E,sum=0,n=0; struct edge { int u; int v; int cost; }; edge *e; bool operator<(const edge& x, const edge& y) { return x.cost < y .cost; } void makeSet(int x) { p[x] = x; rank[x] = 0; } void link(int x, int y) { if(rank[x] > rank[y]) p[y] = x; else { p[x] = y; if(rank[x] == rank[y]) rank[y] = rank[y]+1; } } int findSet(int x) { if(x != p[x]) p[x] = findSet(p[x]); return p[x]; } void unit(int x, int y) { link(findSet(x), findSet(y)); } int kruskal() { sort(e, e+E); for(int i=0; n != V-1; i++) { if(findSet(e[i].u) != findSet(e[i].v)) { unit(e[i].u,e[i].v); sum += e[i].cost; n++; } } } int main() { int s,t,w; cin >> V >> E; p = new int[V]; rank = new int[V]; e = new edge[E]; for(int i=0; i<V; i++) makeSet(i); for(int i=0; i<E; i++) { cin >> s >>t >> w; edge a = {s,t,w}; e[i] = a; } kruskal(); cout << sum << endl; delete[] p,rank,e; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vll; #define all(x) (x).begin(), (x).end() #define endl '\n' #define fsp(x) cout << fixed << setprecision(x) const ll inf = LLONG_MAX; const long double pi = M_PI; void Yes() {cout << "Yes" << endl;} void No() {cout << "No" << endl;} void YES() {cout << "YES" << endl;} void NO() {cout << "NO" << endl;} int main() { ll a, b, c; cin >> a >> b >> c; if ((a <= c && c <= b) || (a >= c && c >= b)) Yes(); else No(); }
#include <stdio.h> int main (){ int N; scanf ("%d", &N); if (N % 10 == 7 || (N/10)%10 == 7 || N /100 == 7){ puts ("Yes"); } else { puts ("No"); } return 0; }
0
// @author PraveenKumarRana #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define int long long int #define vi vector<int> #define pi pair<int, int> #define IOS std::ios_base::sync_with_stdio(false); #define all(x) x.begin(), x.end() #define f(i, a, n) for (int i = a; i < n; i++) #define fr(i, n, a) for (int i = n - 1; i >= a; --i) const int mod = 1e9 + 7; const int inf = 1e16 + 7; void SOLVE() { // Write your code here ? int n, k; cin >> n >> k; map<int, int> mp; f(i, 0, k) { int x; cin >> x; mp[x] = 1; } while (true) { bool ok = true; int N = n; while (N > 9) { if (!mp[N % 10]) { N /= 10; } else { ok = false; break; } } if (N > 0 && !mp[N]) { N /= 10; } else { ok = false; } if (!ok) { N = n + 1; n++; } else { break; } } cout << n << endl; } int32_t main() { IOS; SOLVE(); return 0; }
#include <stdio.h> int main() { int x=0, y= 0, z= 1; scanf("%d\n%d", &x, &y); for (int i = 0; i < x; i++) { if (2 * z <= z + y) { z *= 2; } else { z += y; } } printf("%d\n", z); return 0; }
0
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, s, n) for (int i = s; i < n; i++) #define all(v) v.begin(), v.end() // sort(all(array)) #define INF 1000000000 #define mod 1000000007 using namespace std; using ll = long long; using vi = vector<int>; //vi array(要素数, 初期値) using pll = pair<ll, ll>; using pii = pair<int, int>; using vc = vector<char>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値)) using vvc = vector<vc>; using vvs = vector<vs>; using vvb = vector<vb>; int main() { int n, x, t; cin >> n >> x >> t; if(n % x == 0) { cout << (n / x) * t << endl; } else cout << t + (n / x) * t << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N,K; cin >> N >> K; int X = 1; for(int i = 0; i < N; i++){ if( X * 2 < X + K ){ X = X * 2; } else{ X = X + K; } } cout << X << endl; }
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define reps(i,x,n) for(int i=x; i<(n); i++) #define rrep(i,n) for(int i=(n)-1; i>=0; i--) #define all(X) (X).begin(),(X).end() #define X first #define Y second #define pb push_back #define eb emplace_back using namespace std; typedef long long int ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); } const ll INF = 1e9+7; int main(){ //ios_base::sync_with_stdio(false); int N; vector<pll> v; map<pll, int> mp; cin >> N; rep(i,N){ int x, y; cin >> x >> y; v.emplace_back(x, y); mp[pii(x,y)] = i; } sort(all(v)); vector<int> cv[2]; auto check = [&](int i, int k){ pll a = v[ cv[k][cv[k].size()-2] ]; pll b = v[ cv[k][cv[k].size()-1] ]; pll c = v[i]; if(k == 0) return (b.Y-a.Y) * (c.X-a.X) < (c.Y-a.Y) * (b.X-a.X); if(k == 1) return (b.Y-a.Y) * (c.X-a.X) > (c.Y-a.Y) * (b.X-a.X); }; // rep(k,2) rep(i,N){ // while( cv[k].size() >= 2 && check(i, k) ) cv[k].pop_back(); // cv[k].push_back(i); // } rep(i,N){ int k = 0; while( cv[k].size() >= 2 && check(i, k) ) cv[k].pop_back(); cv[k].push_back(i); } rrep(i,N-1){ int k = 0; while( cv[k].size() >= 2 && check(i, k) ) cv[k].pop_back(); cv[k].push_back(i); } vector<int> convex; for(auto t: cv[0]) convex.push_back(t); rrep(i, cv[1].size()-1) convex.push_back(cv[1][i]); convex.push_back( cv[0][1] ); //for(auto i: convex) cout << v[i].X << "," << v[i].Y << endl; vector<double> ans(N); reps(i, 1, convex.size()-1){ pll a = v[ convex[i-1] ]; pll b = v[ convex[i] ]; pll c = v[ convex[i+1] ]; double vx1 = - (b.Y - a.Y); double vy1 = b.X - a.X; double vx2 = - (c.Y - b.Y); double vy2 = c.X - b.X; double cdot = (vx1*vx2 + vy1*vy2); double l1 = sqrt(vx1*vx1 + vy1*vy1); double l2 = sqrt(vx2*vx2 + vy2*vy2); double ang = acos( cdot / l1 / l2 ); int n = mp[ v[convex[i]] ]; ans[n] = ang / 2.0 / M_PI; } for(auto t: ans) printf("%.20f\n", t); return 0; }
#include <bits/stdc++.h> using namespace std ; const int N = 5010 ; const long long inf = 10000000000000000 ; pair<int,int> zab [ N ] ; bool cmp ( pair<int,int> A, pair<int,int> B ) { return A.first + A.second < B.first + B.second ; } long long dp [ N ][ 3 ]; int main() { // freopen("input.txt", "r", stdin) ; int n ; cin >> n ; for ( int i = 0 ; i < n ; ++i ) cin >> zab[i].first >> zab[i].second ; sort ( zab, zab+n, cmp ) ; int ans =0 ; for ( int i = 1 ; i <= n ; ++i ) { for ( int j = 0 ; j < n ; ++j ) { if ( i == 1 ) dp[j][i%2] = zab[j].first ; else if ( j + i <= n ) dp[j][i%2] = min ( 1ll*zab[j].first, dp[j+1][(i-1)%2] - zab[j].second ); else dp[j][i%2] = -inf ; } bool kPosible = (dp[n-1][i%2] >= 0ll) ; for ( int j = n-2 ; j >= 0 ; --j ) { dp[j][i%2] = max ( dp[j][i%2], dp[j+1][i%2] ) ; kPosible |= (dp[j][i%2]>=0ll) ; } if ( kPosible ) ans = i ; } cout << ans << '\n' ; }
0
// Wanna Hack? GL... #include<bits/stdc++.h> #define F first #define S second #define PB push_back #define sz(s) int((s).size()) #define bit(n,k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int maxn=310,mod=1e9+7; const ll inf=1e18; int dp[2][maxn][maxn]; int main(){ ios_base::sync_with_stdio(false);cin.tie(0); string s;cin>>s; int k,t=0,n=sz(s);cin>>k; for(int r=0;r<n;r++){ dp[0][r][r]=1; for(int l=r-1;l>=0;l--) dp[0][l][r]=max(dp[0][l+1][r],max(dp[0][l][r-1],(s[l]==s[r]?2:0) + dp[0][l+1][r-1])); } for(int i=1;i<=k;i++){ memset(dp[t^1],0,sizeof dp[t^1]); for(int r=0;r<n;r++){ dp[t^1][r][r]=1; for(int l=r-1;l>=0;l--) dp[t^1][l][r]=max(dp[t^1][l+1][r],max(dp[t^1][l][r-1],s[l]==s[r]?2+dp[t^1][l+1][r-1]:2+dp[t][l+1][r-1])); } t^=1; } return cout<<dp[t][0][n-1]<<endl,0; }
#include <bits/stdc++.h> using namespace std; int main(){ string s, t; int N, K, i, j, k; cin >> s; scanf("%d", &K); N = s.size(); t = s; reverse(t.begin(), t.end()); char *S = (char *)malloc(sizeof(char) * (N + 1)); for(i = 1; i <= N; i++){ S[i] = s[i - 1]; } char *T = (char *)malloc(sizeof(char) * (N + 1)); for(i = 1; i <= N; i++){ T[i] = t[i - 1]; } vector<vector<vector<int> > > dp(N + 1, vector<vector<int> >(N + 1, vector<int>(K + 1, 0))); for(i = 1; i <= N; i++){ for(j = 1; j <= N; j++){ dp[i][j][0] = max(dp[i - 1][j][0], dp[i][j - 1][0]); if(S[i] == T[j]){ dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j - 1][0] + 1); } } } for(k = 1; k <= K; k++){ for(i = 1; i <= N; i++){ for(j = 1; j <= N; j++){ dp[i][j][k] = max(max(dp[i - 1][j][k], dp[i][j - 1][k]), dp[i - 1][j - 1][k - 1] + 1); if(S[i] == T[j]){ dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k] + 1); } } } } int ans = 0; for(i = 0; i <= N; i++){ ans = max(ans, 2 * dp[i][N - i][K]); } for(i = 1; i <= N; i++){ ans = max(ans, 2 * dp[i - 1][N - i][K] + 1); } printf("%d\n", ans); return 0; }
1
#include <iostream> #include <string> #include <algorithm> using namespace std; int DP[1010][1010]; int main() { string A, B; cin >> A >> B; int LA = (int) A.size(); int LB = (int) B.size(); fill(&DP[0][0], &DP[0][0]+1010*1010, 0); for (auto i=-1; i<LA; i++) { for (auto j=-1; j<LB; j++) { if (i == -1) { DP[i+1][j+1] = j+1; } else if (j == -1) { DP[i+1][j+1] = i+1; } else if (A[i] == B[j]) { DP[i+1][j+1] = DP[i][j]; } else { // A[i] と B[j] が異なるならば、 // B[j]を挿入するか、A[i]を削除するか、A[i]をB[j]に置換するか // のどれかは必ず実行しなくてはならない。 // 残りの編集作業回数は、それぞれDP[i+1][j]、DP[i][j+1]、DP[i][j] // となる。それぞれが最善である例をつくることができる。 DP[i+1][j+1] = min({DP[i+1][j], DP[i][j+1], DP[i][j]}) + 1; } } } cout << DP[LA][LB] << endl; }
#include<map> #include<set> #include<list> #include<cmath> #include<queue> #include<stack> #include<cstdio> #include<string> #include<vector> #include<complex> #include<cstdlib> #include<cstring> #include<climits> #include<numeric> #include<sstream> #include<iostream> #include<algorithm> #include<functional> #include<cctype> #define mp make_pair #define pb push_back #define REP(i,a,n) for(int i = a;i < (n);i++) #define rep(i,n) for(int i = 0;i < (n);i++) #define all(s) s.begin(), s.end() #define rall(s) s.rbegin(), s.rend() #define range(x,min,max) ((min) <= (x) && (x) <= (max)) using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<vector<int> > VII; typedef vector<string> VS; typedef vector<bool> VB; typedef pair<int,int> PII; const int DX[]={1,0,-1,0},DY[]={0,-1,0,1}; int n, p; int P; VI cnt; int check_winner(){ rep(i, cnt.size()){ if(cnt[i] == P) return i + 1; } return 0; } int solve(){ P = p; int ans; rep(i, 1000000){ rep(j, n){ if(ans = check_winner()){ return ans - 1; }else if(p == 0){ p = cnt[j]; cnt[j] = 0; }else{ p--; cnt[j]++; } } } return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(false); while(1){ cnt.clear(); cin >> n >> p; cnt.resize(n, 0); if(n == 0 && p == 0) break; cout << solve() << endl; } }
0
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using namespace std; template <typename T> using vec = std::vector<T>; int dfs(int now,vec<vec<int>> &G, vec<int> &tpl, vec<bool> &visited){ if(tpl[now] != -1) return tpl[now]; if(tpl[now] == -1 && visited[now]) return -1; visited[now] = true; if(G[now].size() == 0) { tpl[now] = 1; return 1; } int tmpOrder = -1; for(auto e:G[now]){ int tmp = dfs(e,G,tpl,visited); if(tmp == -1) return -1; tmpOrder = max(tmpOrder,tmp+1); } tpl[now] = tmpOrder; return tpl[now]; } vector<int> topological_sort(vec<vec<int>> &G){ int N = G.size(); vec<int> topolo(N,-1); vec<bool> visited(N,false); rep(i,N) dfs(i,G,topolo,visited); // {-1,-1,-1,…} の時はトポロジカルソート不可 return topolo; } int main() { int N; cin >> N; vec<vec<int>> A(N, vec<int>(N - 1)); rep(i, N) rep(j, N - 1) { cin >> A[i][j]; --A[i][j]; } vec<vec<int>> id(N, vec<int>(N, -1)); int now = 0; rep(i, N) rep(j, N) { if (i == j || i > j) continue; id[i][j] = now, ++now; } vec<vec<int>> games(N,vec<int>(N-1)); rep(i, N) rep(j, N - 1) { int me = i; int vs = A[i][j]; if (me > vs) swap(me, vs); games[i][j] = id[me][vs]; } vec<vec<int>> G(now,vec<int>()); rep(i,N)rep(j,N-2){ G[games[i][j+1]].push_back(games[i][j]); } vec<int> a = topological_sort(G); int ans = 0; for(auto e:a) { if(e==-1) { cout << -1 << endl; return 0; } ans= max(ans,e); } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long int #define endl '\n' #define M 1000000007 #define yes cout<<"YES\n" #define no cout<<"NO\n" #define f first #define s second #define b begin #define e end #define pb push_back #define mp make_pair #define FOR(i,a,b) for(i=a;i<b;i++) #define RFOR(i,a,b) for(i=a;i>=b;i--) #define all(x) x.begin(),x.end() #define itfr(it,x) for(it=x.begin();it!=x.end();it++) #define flash ios_base::sync_with_stdio(false); cin.tie(NULL) using namespace std; int main() { flash; //sieve(); ll T=1,t,n,m,q,k,i,j; // cin>>T; while(T--) { n=5; ll a[n]; FOR(i,0,n) cin>>a[i]; cin>>k; int fl=1; FOR(i,0,n) { FOR(j,0,n) if((a[j]-a[i])>k) fl=0; } if(fl) cout<<"Yay!"; else cout<<":("; } }
0
#include <iostream> int main() { int n; std::cin >> n; std::string line; std::getline(std::cin, line); while (n--) { std::getline(std::cin, line); int i; while ((i = line.find("Hoshino")) != std::string::npos) { line.replace(i, 7, "Hoshina"); } std::cout << line << std::endl; } return 0; }
#include <stdio.h> int main(){ char name[12]; scanf("%[^\n]", &name); name[3] = '8'; printf("%s", name); return 0; }
0
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<iterator> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define FOR(i,x,n) for(int i=x; i<(n); i++) #define vint(a,n) vint a(n); rep(i, n) cin >> a[i]; #define vll(a,n) vll a(n); rep(i, n) cin >> a[i]; #define ALL(n) begin(n),end(n) #define RALL(n) rbegin(n),rend(n) #define MOD (1000000007) #define INF (2e9) #define INFL (2e18) typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; using vint=vector<int>; using vll=vector<ll>; using vbool=vector<bool>; template<class T>using arr=vector<vector<T>>; template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;} template<class T>void pr(T x){cout << x << endl;} template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);} template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int main() { ll a, b; cin >> a >> b; if(b>a) swap(a, b); map<ll, int> m; for(ll i=2;i*i<=b;i++){ while(b!=1 && b%i==0){ if(a%i==0) m[i]++; b/=i; } } if(b!=1 && a%b==0) m[b]++; pr(m.size()+1); return 0;}
#include<bits/stdc++.h> using namespace std; //mod逆元を使ったnCkの計算(速) const int64_t MAX = 510000; const int64_t MOD = 1000000007; int64_t fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int64_t COM(int64_t n, int64_t k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { // input from txt (提出時にこの箇所は削除すること) //std::ifstream in("input.txt"); //std::cin.rdbuf(in.rdbuf()); int64_t N, M; cin >> N >> M; COMinit(); int64_t n = M; //素因数分解 map<int64_t,int64_t> mp; int a = 2; while(n >= a*a){ if(n %a == 0){ if(mp.count(a)){ mp[a]++; } else{ mp[a] = 1; } n /= a; } else{ a++; } } if(mp.count(n)){ mp[n]++; } else{ mp[n] = 1; } int64_t ans = 1; for(auto itr = mp.begin(); itr != mp.end(); itr++){ int64_t x = itr->second; //cout << x << endl; ans *= COM(x+N-1,N-1); ans %= MOD; } if(M == 1){ ans = 1; } cout << ans << endl; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a) for(int i=0;i<(a);i++) const ll MOD=1000000007; int N; ll D,A[202020]; vector<pair<ll,pair<int,int>>> G; const int MAX_V=202020; int par[MAX_V]; // 親 int rnk[MAX_V]; // rank, 木の深さ void init(){ for(int i=0;i<MAX_V;i++){ par[i]=i; rnk[i]=0; } } int find(int x){ if (par[x] == x){ return x; }else{ return par[x] = find(par[x]); } } void unite(int x, int y){ x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]){ par[x] = y; }else{ par[y] = x; if (rnk[x] == rnk[y]) rnk[x]++; } } bool same(int x, int y){ return find(x) == find(y); } void solve(int l, int r){ if(r-l<=1) return; int mid=(l+r)/2; int miL=l; for(int i=l+1;i<mid;i++) if(A[i]-D*i<A[miL]-miL*D) miL=i; int miR=mid; for(int i=mid+1;i<r;i++) if(A[i]+D*i<A[miR]+miR*D) miR=i; for(int i=mid;i<r;i++) G.push_back({A[i]+A[miL]+D*(i-miL),{i,miL}}); for(int i=l;i<mid;i++) G.push_back({A[i]+A[miR]+D*(miR-i),{i,miR}}); solve(l,mid); solve(mid,r); } int main(){ cin>>N>>D; rep(i,N) cin>>A[i]; solve(0,N); sort(G.begin(),G.end()); init(); ll ans=0; for(auto& p:G){ if(!same(p.second.first,p.second.second)){ ans+=p.first; unite(p.second.first,p.second.second); } } cout<<ans<<endl; return 0; }
#include<cstdio> #include<cmath> #include<algorithm> #include<vector> using namespace std; typedef long long ll; typedef pair<ll,int> pli; #define fir first #define sec second #define Mp make_pair const int MAXN = 2e5 + 5; const int inf = 0x3f3f3f3f; const ll linf = 0x3f3f3f3f3f3f3f3f; template<typename T> void chk_min(T &a,T b){ if(a>b) a=b;} ll a[MAXN]; int main(void) { int n; ll d; scanf("%d%lld",&n,&d); for(int i=1; i<=n; ++i) scanf("%lld",&a[i]); ll ans=0; for(int i=1; i<=n; ++i) ans += a[i]; for(int i=2; i<=n; ++i) chk_min(a[i], a[i-1]+d); for(int i=n-1; i>=1; --i) chk_min(a[i], a[i+1]+d); for(int i=1; i<=n; ++i) ans += a[i]; printf("%lld",ans + d*(n-1) - a[1] - a[n]); return 0; }
1
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) typedef int64_t Int; typedef pair<int,int> P; vector<int> num = {0,2,5,5,4,5,6,3,7,6}; string maxs(string S, string T){ if(S.length() > T.length()){ return S; } else if (S.length() < T.length()){ return T; } else { return (S < T) ? T : S; } } int main(){ int N, M; vector<int> A(9); cin >> N >> M; rep(i,M) cin >> A[i]; // dp[i]: マッチちょうどi本で作れる最大値 vector<string> dp(10010, ""); rep(i,N) rep(j,M){ if(dp[i] == "" && i != 0) continue; char c = A[j] + '0'; if(i+num[A[j]] <= N){ string next = dp[i] + c; dp[i+num[A[j]]] = maxs(dp[i+num[A[j]]], next); } } cout << dp[N] << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int match[10]={0,2,5,5,4,5,6,3,7,6}; int n,m; cin>>n>>m; int a[m],x[m]; for(int i=0;i<m;i++)cin>>a[i]; sort(a,a+m,greater<int>()); for(int i=0;i<m;i++)x[i]=match[a[i]]; vector<int>dp(n+1,-1000000000); dp[0]=0; for(int i=0;i<n-1;i++){ for(int j=0;j<m;j++)if(i+x[j]<=n)dp[i+x[j]]=max(dp[i+x[j]],dp[i]+1); } while(n){ for(int i=0;i<m;i++){ if(n-x[i]>=0 && dp[n-x[i]]==dp[n]-1){ cout<<a[i]; n-=x[i]; break; } } } cout<<endl; return 0; }
1
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; // #define int ll #define REP(i,n) for (int i = 0; i < (n); ++i) #define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++) #define debug(x) cerr << #x << ": " << x << '\n' const int MOD = (int)1e9 + 7; int main() { int N; cin >> N; vector<int> vec(N); REP(i, N) { cin >> vec.at(i); } // 偶数indで、一番多いものに合わせる map<int, int> even_map; for(int i = 0; i < N; i+=2) { int val = vec[i]; if (even_map.count(val) == 1) { even_map[val] += 1; } else { even_map[val] = 1; } } // 奇数indで、一番多いものに合わせる map<int, int> odd_map; for(int i = 1; i < N; i+=2) { int val = vec[i]; if (odd_map.count(val) == 1) { odd_map[val] += 1; } else { odd_map[val] = 1; } } int odd_most_freq = -1; int odd_most_freq_cnt = 0; int odd_2nd_most_freq; int odd_2nd_most_freq_cnt = 0; for (auto x : odd_map){ int key = x.first; int value = x.second; if (value > odd_most_freq_cnt) { odd_2nd_most_freq = odd_most_freq; odd_2nd_most_freq_cnt = odd_most_freq_cnt; odd_most_freq = key; odd_most_freq_cnt = value; } else if (value > odd_2nd_most_freq_cnt) { odd_2nd_most_freq = key; odd_2nd_most_freq_cnt = value; } } int even_most_freq = 0; int even_most_freq_cnt = 0; int even_2nd_most_freq; int even_2nd_most_freq_cnt = 0; for (auto x : even_map){ int key = x.first; int value = x.second; debug(key); debug(value); if (value > even_most_freq_cnt) { even_2nd_most_freq = even_most_freq; even_2nd_most_freq_cnt = even_most_freq_cnt; even_most_freq = key; even_most_freq_cnt = value; } else if (value > even_2nd_most_freq_cnt) { even_2nd_most_freq = key; even_2nd_most_freq_cnt = value; } } // REP(i, N) { // int v = vec.at(i); // debug(v); // } debug(even_most_freq); debug(even_most_freq_cnt); debug(even_2nd_most_freq); debug(even_2nd_most_freq); debug(odd_most_freq); debug(odd_most_freq_cnt); debug(odd_2nd_most_freq); debug(odd_2nd_most_freq); int evens = N % 2 == 0 ? (N / 2) : (N+1) / 2; debug(evens); int ans_even = evens - even_most_freq_cnt; debug(ans_even); int odds = N / 2; debug(odds); int ans_odd = odds - odd_most_freq_cnt; debug(ans_odd); if (even_most_freq == odd_most_freq) { int a = odds - odd_2nd_most_freq_cnt + ans_even; int b = evens - even_2nd_most_freq_cnt + ans_odd; int c = a < b ? a : b; cout << c << endl; return 0; } cout << ans_even + ans_odd << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) using ll = long long; using namespace std; const int INF = 1e9; int main() { int n; cin >> n; string s[3]; rep(i, 3) cin >> s[i]; int ans = 0; rep(i, n) { set<char> st; rep(j, 3) st.insert(s[j][i]); ans += st.size() - 1; } cout << ans << endl; return 0; }
0
#include <bits/stdc++.h> typedef std::pair<int, int> pii; namespace IO { const int lim = 1 << 20 | 50; char buf[lim + 5], *S, *T; inline char gc() { if (S == T) { T = (S = buf) + fread(buf, 1, lim, stdin); if (S == T) return EOF; } return *S++; } inline int read() { int x; bool f; char c; for (f = 0; (c = gc()) < '0' || c > '9'; f = c == '-'); for (x = c ^ '0'; (c = gc()) >= '0' && c <= '9'; x = x * 10 + c - '0'); return f ? -x : x; } } const int MN = 1e5 + 5, MV = 5e5 + 5; std::map<pii, int> mp; int n, m, dist[MV], vn; bool vis[MV]; std::deque<int> q; std::vector<int> G[MV]; void solve() { memset(dist, 0x3f, sizeof dist); dist[1] = 0; q.push_back(1); for (; !q.empty(); ) { int u = q.front(); q.pop_front(); if (vis[u]) continue; vis[u] = 1; for (unsigned int i = 0; i < G[u].size(); ++i) { int v = G[u][i]; if (vis[v] || (dist[u] + (u <= n)) >= dist[v]) continue; dist[v] = dist[u] + (u <= n); if (u <= n) q.push_back(v); else q.push_front(v); } } } int main() { vn = n = IO::read(); for (m = IO::read(); m; --m) { int x = IO::read(), y = IO::read(), c = IO::read(); if (mp.find(pii(x, c)) == mp.end()) { mp[pii(x, c)] = ++vn; G[vn].push_back(x); G[x].push_back(vn); } if (mp.find(pii(y, c)) == mp.end()) { mp[pii(y, c)] = ++vn; G[vn].push_back(y); G[y].push_back(vn); } x = mp[pii(x, c)]; y = mp[pii(y, c)]; G[x].push_back(y); G[y].push_back(x); } solve(); printf("%d\n", dist[n] == 0x3f3f3f3f ? -1 : dist[n]); return 0; } /* 8 11 1 3 1 1 4 2 2 3 1 2 5 1 3 4 3 3 6 3 3 7 3 4 8 4 5 6 1 6 7 5 7 8 5 */
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define i128 __int128 #define mp make_pair #define ld long double typedef pair<int, int> pii; typedef priority_queue<int, vector<int>, greater<int> > small_heap; typedef priority_queue<int> big_heap; const int N = 1e6 + 100; int T; int a, b, m; int aa[N], bb[N]; pair<pii, int> c[N]; int main() { ios::sync_with_stdio(false); cin >> a >> b >> m; for (int i = 1; i <= a; i++)cin >> aa[i]; for (int i = 1; i <= b; i++)cin >> bb[i]; for (int i = 1; i <= m; i++)cin >> c[i].first.first >> c[i].first.second >> c[i].second; int ans = *min_element(aa + 1, aa + a + 1) + *min_element(bb + 1, bb + b + 1); for (int i = 1; i <= m; i++) { ans = min(ans, aa[c[i].first.first] + bb[c[i].first.second] - c[i].second); } cout << ans << endl; return 0; }
0
#include<iostream> #include<string> #include<algorithm> using namespace std; int main() { string a, b, c; int flag = 0; int sa = 0, sb = 0,sc = 0; cin >> a >> b >> c; while (1) { while (flag == 0) { if (a[sa] == 'a')flag = 0; else if (a[sa] == 'b')flag = 1; else if (a[sa] == 'c')flag = 2; else if (a[sa] == '\0') { cout << 'A' << endl; return 0; } sa++; } while (flag == 1) { if (b[sb] == 'a')flag = 0; else if (b[sb] == 'b')flag = 1; else if (b[sb] == 'c')flag = 2; else if (b[sb] == '\0') { cout << 'B' << endl; return 0; } sb++; } while (flag == 2) { if (c[sc] == 'a')flag = 0; else if (c[sc] == 'b')flag = 1; else if (c[sc] == 'c')flag = 2; else if (c[sc] == '\0') { cout << 'C' << endl; return 0; } sc++; } } }
#include <iostream> #include <string.h> #include <algorithm> #include <vector> #include <fstream> using namespace std; ifstream fin("../data.txt"); char sa[104], sb[104], sc[104], *s; int ia, ib, ic, *i; char winner; int main() { cin.getline(sa, 104); cin.getline(sb, 104); cin.getline(sc, 104); s = sa; i = &ia; while (*i < strlen(s)) { *i += 1; if (s[(*i)-1] == 'a') { s = sa; i = &ia; winner = 'A'; } else if (s[(*i)-1] == 'b') { s = sb; i = &ib; winner = 'B'; } else if (s[(*i)-1] == 'c') { s = sc; i = &ic; winner = 'C'; } } cout << winner; return 0; }
1
#include <bits/stdc++.h> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; using lb = long double; using P = pair<ll,ll>; using graph = vector<vector<ll>>; using V = vector<ll>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll INF = 1LL<<60; const ll mod = 1000000007LL; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll hcnt[300005],wcnt[300005]; int main() { ll N,K; cin>>N>>K; vector<ll> v(N); rep(i,N) cin>>v[i]; ll ans = -INF; rep(i,N+1){ rep(j,N-i+1){ if(i+j>K)continue; priority_queue<ll,vector<ll>,greater<ll>> q; rep(k,i) q.push(v[k]); rep(k,j) q.push(v[N-k-1]); rep(k,K-i-j){ if(q.empty()) break; if(q.top()<0) q.pop(); } ll cnt = 0; while(!q.empty()) { cnt += q.top(); q.pop(); } chmax(ans,cnt); } } cout<<ans<<endl; }
#include <bits/stdc++.h>//Carefully Crafted by hetp111 using namespace std; #define int long long #define double long double #define all(v) (v).begin(),(v).end() #define vi vector<int> #define vvi vector<vi> #define pii pair<int,int> #define vii vector<pii> #define MOD 1000000007 #define MOD2 998244353 #define MOD3 1000000009 #define PI acos(-1) #define eps (1e-8) #define INF (1e18) #define FASTER ios_base::sync_with_stdio(0);cin.tie(0) template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";} template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;} template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;} template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;} //ifstream cinn("in.in");ofstream coutt("out.out"); int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;} int ceil(const int &a,const int &b){return (a+b-1)/b;} ////Read: //Check corner cases, n==1; // ////Some function: //__builtin_popcountll(), int n,c,dp[55][55][55][55]; vi v; int f(int i,int cnt,int mxgap,int lst){ if(i==n){ mxgap=max(mxgap,i-lst-1); if(cnt+(n-cnt-mxgap)*2<=c)return 0; return -INF; } int &ans=dp[i][cnt][mxgap][lst+1]; if(ans!=-INF)return ans; ans=v[i]+f(i+1,cnt+1,max(mxgap,i-lst-1),i); ans=max(ans,f(i+1,cnt,mxgap,lst)); return ans; } signed main(){ FASTER; cin>>n>>c; v=vi(n);cin>>v; for(int i=0;i<55;i++){ for(int j=0;j<55;j++){ for(int k=0;k<55;k++){ for(int l=0;l<55;l++){ dp[i][j][k][l]=-INF; } } } } cout<<f(0,0,0,-1); }
1
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0)->sync_with_stdio(false); string s; cin >> s; map<char, bool> a; REP(i, 26) a['a' + i] = false; int n = s.size(); REP(i, n) a[s[i]] = true; int cnt = 0; for (auto i : a) if (i.second == true) cnt++; string ans; if (cnt != 26) { char c; for (auto i : a) if (i.second == false) { c = i.first; break ; } ans = s + c; } else if (cnt == 26) { int index = n - 1; for (int i = n - 1; i > 0; i--) { if (s[i - 1] - s[i] > 0) index = i - 1; else break ; } if (index == 0) ans = "-1"; else { string tmp = s.substr(index); sort(tmp.begin(), tmp.end()); char c; REP(i, tmp.size()) if (tmp[i] > s[index - 1]) { c = tmp[i]; break ; } s.erase(index - 1); ans = s + c; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; // 型定義 typedef long long ll; typedef pair<ll, ll> P; // forループ #define REP(i,n) for(ll i=0; i<(ll)(n); ++i) // 定数宣言 const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; // グラフ表現 using Graph = vector<vector<int>>; // グラフの辺表現 using Edge = map<pair<int,int>,int>; // n次元配列の初期化。第2引数の型のサイズごとに初期化していく。 template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } // 最大公約数 ll gcd(ll a,ll b){ if (a%b == 0) return(b); else return(gcd(b, a%b)); } // 最小公倍数 ll lcm(ll a, ll b){ return a*b/gcd(a, b); } int main() { cout << fixed << setprecision(15); string S; cin >> S; ll N = S.length(); map<char, bool> A; REP(i, N){ A[S[i]] = true; } if(N<26){ cout << S; REP(i, 26){ // cout << char(i+'a') << endl; char c = char(i+'a'); if(!A.count(c)){ cout << c << endl; return 0; } } } vector<char> T; for(ll i=25; i>=0; i--){ if(i ==25){ T.push_back(S[i]); continue; } // cout << S[i] << endl; sort(T.begin(), T.end()); // cout << T[0] << endl; if(i==0){ if(S[0] != 'z'){ cout << char(S[0]+1) << endl; } else{ cout << -1 << endl; } return 0; } else if(S[i] < T[T.size()-1]){ REP(j, i){ cout << S[j]; } for(auto v: T){ if(v > S[i]){ cout << v << endl; return 0; } } } T.push_back(S[i]); } return 0; }
1
// Believe in yourself #include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; #define PB push_back #define MP make_pair #define F first #define S second #define Pair vector<pair<ll,ll>> #define vec vector <ll> #define all(a) a.begin(),a.end() #define mo 1000000007 #define decimal(i,n) fixed << setprecision(i) << n #define show(a) for(auto xyz:a)cout<<xyz<<" ";cout<<endl; #define show_nl(a) for(auto xyz:a)cout<<xyz<<endl; void eea(ll a,ll b,ll &x,ll &y) { if (a == 1) { x = 1; y = 0; return; } ll x1, y1; eea(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; } ll mi(ll a,ll m) { ll x,y; eea(a,m,x,y); x= (x%m+m)%m; return x; } /* Enter the test case Some helpful points 1.) Calm yourself 2.) check for semicolon or data type mismatch */ int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t=1; // cin>>t; while(t--) { int n,k; cin>>n>>k; double a[n]; double s=0; double ans=0; for(int i=0;i<n;i++) { cin>>a[i]; a[i]=a[i]+1; } for(int i=0;i<k;i++) s=s+a[i]; for(int i=k;i<n;i++) { if(ans<s) ans=s; s=s-a[i-k]+a[i]; } if(ans<s) ans=s; cout<<decimal(9,ans/2)<<"\n"; } }
#include <bits/stdc++.h> using namespace std; // D - Dice in Line int main() { int N, K; cin >> N >> K; long double p[N]; int tmpP; for (int i = 0; i < N; i++) { cin >> tmpP; p[i] = ((tmpP + 1.0) / 2.0); } /* // debug for (int i = 0; i < N; i++) { cout << p[i] << endl; } */ long double nowSum = 0, maxSum = 0; for (int i = 0; i < K; i++) { nowSum = nowSum + p[i]; } // cout << "nowSum:" << nowSum << endl; // debug maxSum = nowSum; for (int i = K; i < N; i++) { nowSum = nowSum - p[i - K] + p[i]; maxSum = max(nowSum, maxSum); } // cout << maxSum; printf("%Lf", maxSum); }
1
#include<stdio.h> int main(){ char year[10], month[5], day[5]; scanf("%[^/]/%[^/]/%s", &year, &month, &day); getchar(); printf("2018/01/%s\n", day); return 0; }
#include <iostream> #include <algorithm> #include <stack> #include <string> #include <queue> #include <cstdlib> #include <cstdio> #include <vector> #include <list> #include <string.h> #define _USE_MATH_DEFINES #include <math.h> using namespace std; int Partition(int a[], int p, int r) { int x = a[r]; int i = p-1; for(int j = p; j < r; j++) { if(a[j] <= x) { i++; int temp = a[i]; a[i] = a[j]; a[j] = temp; } } int temp = a[i+1]; a[i+1] = x; a[r] = temp; return i+1; } int main() { int n; cin >> n; int a[n]; for( int i = 0; i < n; i++) cin >> a[i]; int b = Partition(a, 0, n-1); for( int i = 0; i < n; i++) { if(i == b) { if( i ) cout << " [" <<a[i] << "]"; else cout << "[" << a[i] << "]"; } else if( i ) cout << " " <<a[i]; else cout << a[i]; } cout << endl; return 0; }
0
#include <stdio.h> #include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long #define rep2(i,a,b) for(ll i=a;i<=b;++i) #define rep(i,n) for(ll i=0;i<n;i++) #define rep3(i,a,b) for(ll i=a;i>=b;i--) #define REP(e,v) for(auto e:v) #define pii pair<int,int> #define pll pair<ll,ll> #define tii tuple<int,int,int> #define pq priority_queue<int> #define pqg priority_queue<int,vector<int>,greater<int>> #define pb push_back #define edge(v,a,b) v[a].pb(b);v[b].pb(a); #define MAX_V 400010 #define vec vector<int> #define vecll vector<ll> #define vecpii vector<pii> #define endl "\n" #define ALL(c) (c).begin(),(c).end() using namespace std; int in() {int x;scanf("%d",&x);return x;} ll lin() {ll x;scanf("%lld",&x);return x;} #define INF 1e9+7 #define LLINF 1e18+7 ll MOD=1e9+7; #define N 1055050 ll dp[50][1<<20]; bool judge[N]; ll pw[50]; main(){ ios_base::sync_with_stdio(false); int n=in(); int x[3]; rep(i,3)x[i]=in(); int sum=x[0]+x[1]+x[2]; ll ans=0; pw[0]=1; rep(i,20)pw[i+1]=pw[i]*2; dp[0][0]=1; vec all; rep(i,1<<sum){ if((i&(1<<(x[2]-1))&&(i&(1<<(x[2]+x[1]-1))&&(i&1<<(sum-1)))))judge[i]=1; else all.pb(i); } rep(i,n){ for(auto k:all){ if(dp[i][k]==0)continue; rep2(j,1,7){ ll next=(k*pw[j]+pw[j-1])%pw[sum]; if(!judge[next]) dp[i+1][next]=(dp[i][k]+dp[i+1][next])%MOD; } dp[i+1][0]=(dp[i+1][0]+dp[i][k]*3)%MOD; } } ll p=1; rep(i,n){ p=p*10ll%MOD; } rep(i,1<<sum){ p=(p-dp[n][i]+MOD)%MOD; } cout<<p<<endl; }
#include <bits/stdc++.h> using namespace std; #define sz(x) (int) x.size() #define all(a) a.begin(), a.end() const int mod = (int) 1e9 + 7; int n; int x, y, z; map <vector<int>, int> mp; vector<int> seq[205000]; int len[205000]; int seqSum[205000]; bool haiku[205000]; int cnt; int mxSum = 0; int mxNum = 0; bool check(vector<int>& v) { int p = 0; int xx = x, yy = y, zz = z; while (p < sz(v) && xx > 0) { xx -= v[p]; p++; } while (p < sz(v) && yy > 0) { yy -= v[p]; p++; } while (p < sz(v) && zz > 0) { zz -= v[p]; p++; } return xx == 0 && yy == 0 && zz == 0 && p == sz(v); } void go(vector<int>& v, int sum) { mp[v] = cnt; len[cnt] = sz(v); seq[cnt] = v; seqSum[cnt] = sum; haiku[cnt] = check(v); cnt++; for (int i = 1; i <= min(mxNum, mxSum - sum); i++) { v.push_back(i); go(v, sum + i); v.pop_back(); } } long long dp[45][2][130500]; int mv[130500][12]; int main() { cin >> n >> x >> y >> z; mxSum = x + y + z; mxNum = max(max(x, y), z); vector<int> v; go(v, 0); // cerr << cnt << endl; for (int i = 0; i < cnt; i++) { for (int num = 1; num <= mxNum; num++) { int sum = seqSum[i] + num; int p = 0; while (p < sz(seq[i]) && sum > mxSum) { sum -= seq[i][p]; p++; } vector<int> go; while (p < sz(seq[i])) { go.push_back(seq[i][p]); p++; } go.push_back(num); mv[i][num] = mp[go]; } } dp[0][0][0] = true; for (int i = 0; i < n; i++) for (int j = 0; j <= 1; j++) for (int k = 0; k < cnt; k++) { if (dp[i][j][k] == 0) continue; if (haiku[k] && j == 0) continue; if (len[k] > i) continue; for (int num = 1; num <= mxNum; num++) { int goK = mv[k][num]; dp[i + 1][j | haiku[goK]][goK] = (dp[i + 1][j | haiku[goK]][goK] + dp[i][j][k]) % mod; } dp[i + 1][j][0] = (dp[i + 1][j][0] + dp[i][j][k] * (10 - mxNum)) % mod; } long long ans = 0; for (int i = 0; i < cnt; i++) ans = (ans + dp[n][1][i]) % mod; cout << ans << endl; return 0; }
1
#pragma GCC optimize ("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse4") #include"bits/stdc++.h" using namespace std; typedef long long ll; #define int ll #define sz(x) (int)(x).size(); #define all(x) x.begin(), x.end() #define trav(i,a) for(auto &i:a) inline int in(){int x;scanf("%lld",&x);return x;} int h[10]={0,2,5,5,4,5,6,3,7,6}; int32_t main() { int n=in();int m=in(); vector<char> a(m); trav(i,a)cin>>i; vector<string> dp(n+10); //dp[i] best answer with i sticks //making only given digits from a(m) dp[0]=""; for(int i=0;i<m;i++) { dp[h[a[i]-'0']]=max(dp[h[a[i]-'0']],(string)""+a[i]); } for(int i=0;i<=n;i++) { for(int j=0;j<m;j++) { if(dp[i]=="")continue; if((i+h[a[j]-'0'])>n)continue; if(dp[i+h[a[j]-'0']].size()>dp[i].size()+1)continue; if(dp[i+h[a[j]-'0']].size()<dp[i].size()+1) { dp[i+h[a[j]-'0']]=dp[i]+a[j]; } else dp[i+h[a[j]-'0']]=max(dp[i]+a[j],dp[i+h[a[j]-'0']]); } } cout<<dp[n]; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif ll n, m; struct numinfo { int digit; int match; int min_match; int n; }; vector<numinfo> nums; bool dfs( int i, int remain_match, int remain_keta ){ if ( i == SZ(nums) ){ eprintf( "remain=%d %d ", remain_match, remain_keta ); rep(k,SZ(nums)){ eprintf( "%d ", (int)nums[k].n ); } eprintf( "\n" ); if ( remain_match == 0 && remain_keta <= 0 ) return true; return false; } for ( int k = remain_match/nums[i].match; k >= 0; k-- ){ nums[i].n = k; int creatable_keta = (remain_match-k*nums[i].match)/nums[i].min_match; if ( remain_keta-k-creatable_keta > 0 ) continue; if ( dfs( i+1, remain_match-k*nums[i].match, remain_keta-k ) ) return true; } return false; } int main(){ cin >> n >> m; vector<int> a(m); rep(i,m){ cin >> a[i]; } sort(a.rbegin(),a.rend()); int digit_to_match[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 }; set<int> s; rep(i,m){ int match = digit_to_match[a[i]]; if ( s.count(match) == 0 ) nums.push_back({a[i],match,100,0}); s.insert(match); } m = nums.size(); int min_match = 100; for ( int i = nums.size()-1; i >= 0; i-- ){ nums[i].min_match = min_match; chmin(min_match, nums[i].match); eprintf( "digit,=%d match=%d min_match=%d\n", nums[i].digit, nums[i].match, nums[i].min_match ); } for ( int keta = n / min_match; keta > 0; keta-- ){ eprintf( "\n\nketa=%d\n", keta ); if ( dfs( 0, n, keta ) ){ sort(nums.begin(), nums.end(), [](numinfo &l, numinfo &r){ return l.digit>r.digit; }); rep(i,m){ rep(j,nums[i].n){ cout << nums[i].digit; } } cout << endl; return 0; } } return 0; }
1
#include <bits/stdc++.h> #define pb push_back #define ll long long #define f first #define s second using namespace std; int n, a[100005]; vector<pair<int,int>> vec, vec2; unordered_map<int,int> mp, mp2; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef debug freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n; for(int i = 1; i <= n; i++)cin >> a[i]; for(int i = 1; i <= n; i+= 2)mp[a[i]]++; for(int i = 2; i <= n; i += 2)mp2[a[i]]++; for(auto i : mp)vec.pb({i.s, i.f}); for(auto i : mp2)vec2.pb({i.s, i.f}); sort(vec.begin(), vec.end()); sort(vec2.begin(), vec2.end()); int cnt = 1e9; int delta = n/2; if(vec.size() == 1 && vec2.size() == 1){ if(vec[0].s == vec2[0].s){ cnt = delta; } else{ cnt = 0; } } else{ if(vec[vec.size()-1].s != vec2[vec2.size()-1].s){ cnt = delta - vec[vec.size()-1].f + delta - vec2[vec2.size()-1].f; } else{ if(vec.size() > 1)cnt = min(cnt, delta - vec2[vec2.size()-1].f + delta - vec[vec.size()-2].f); else cnt = min(cnt, delta + delta - vec2[vec2.size()-1].f); if(vec2.size() > 1)cnt = min(cnt, delta - vec2[vec2.size()-2].f + delta - vec[vec.size()-1].f); else cnt = min(cnt, delta + delta - vec[vec.size()-1].f); } } cout << cnt << endl; return 0; }
#include<cstdio> #include<algorithm> using ll = long long; struct edge{int u, v, cost;}; const static int MAX_N = 100000; int par[MAX_N]; int rank[MAX_N]; void init_union_find(int n){ for (int i = 0; i < n; ++i){ par[i] = i; rank[i] = 0; } } int find(int x){ if(par[x] == x) return x; else return par[x] = find(par[x]); } void unite(int x, int y){ x = find(x); y = find(y); if(x == y) return; if(rank[x] < rank[y]){ par[x] = y; }else{ par[y] = x; if(rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y){ return find(x) == find(y); } bool comp(const edge& e1, const edge& e2){ return e1.cost < e2.cost; } int main(){ int N; scanf("%d", &N); std::pair<int, int> x[N], y[N]; for (int i = 0; i < N; ++i){ x[i].second = y[i].second = i; scanf("%d %d", &x[i].first, &y[i].first); } std::sort(x, x + N), std::sort(y, y + N); edge es[2*(N - 1)]; for (int i = 0; i < N - 1; ++i){ es[i].u = x[i].second; es[i].v = x[i + 1].second; es[i].cost = x[i + 1].first - x[i].first; } for (int i = N - 1; i < 2*(N - 1); ++i){ es[i].u = y[i + 1 - N].second; es[i].v = y[i + 2 - N].second; es[i].cost = y[i + 2 - N].first - y[i + 1 - N].first; } std::sort(es, es + 2*(N - 1), comp); init_union_find(N); int total = 0; for (int i = 0; i < 2*(N - 1); ++i){ edge e = es[i]; if(!same(e.u, e.v)){ unite(e.u, e.v); total += e.cost; } } printf("%d\n", total); return 0; }
0
#include <iostream> using namespace std; int main(){ float d,t,s; cin>>d>>t>>s; float time = d/s; if (time > t){ cout<<"No"; } else{ cout<<"Yes"; } }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, n) for(int i = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define MP make_pair #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1 << 30; const ll LINF = 1LL << 61; const int MOD = 1e9 + 7; int main() { int N, H, W; cin >> N >> H >> W; cout << (N - W + 1) * (N - H + 1) << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define int ll #define _GLIBCXX_DEBUG #define REP(i,n) for (int i = 0; i < (n); ++i) #define REPD(i,n) for (int i = (n-1); i >= 0; --i) #define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++) #define debug(x) cerr << #x << ": " << x << '\n' #define hyphen() cerr << "--\n" #define ALL(vec) (vec).begin(), (vec).end() #define REVALL(vec) (vec).rbegin(), (vec).rend() #define fst first #define pb push_back const int MOD = (int)1e9 + 7; const int INF = numeric_limits<int>::max(); const int BIT = 10; signed main() { int D, G; cin >> D >> G; vector<int> Ps(D); vector<int> Cs(D); REP(i, D) { cin >> Ps.at(i) >> Cs.at(i); } // どの問題をコンプリートしたかは、10ビットで表現できる。 // そこから、それ以上コンプリートしないように注意しつつ、高い配点の問題から解いていく int ans = INF; REP(tmp, (1 << D)) { bitset<BIT> bs(tmp); int score = 0; int solved = 0; REP(i, D) { if (bs.test(i)) { solved += Ps[i]; score += 100 * (i+1) * Ps[i] + Cs[i]; } } // もし既に達成していたら、それでOK if (score >= G) { if (solved < ans) { ans = solved; debug(bs); debug(score); debug(solved); hyphen(); } continue; } // 達成していない場合は、ポイントの高い問題から解いていく REPD(i, D) { if (bs.test(i)) { continue; } if (Ps[i] == 1) { continue; } int point = 100 * (i+1); int solve_but_one_score = score + (point * (Ps[i] - 1)); if (solve_but_one_score < G) { // まだ足りない → 次へ score = solve_but_one_score; solved += (Ps[i] - 1); continue; } else { // 足りた → 解き過ぎないようにして〆 // ceilはx.00001の時がこわい int solved_this; if ((G - score) % point == 0) { solved_this = (G - score) / point; } else { solved_this = (G - score) / point + 1; } score += point * solved_this; solved += solved_this; if (solved < ans) { ans = solved; debug(bs); debug(score); debug(solved); hyphen(); } break; } } // ここに辿り着いた時には、もう打つ手立てが無いので、 // 更新処理を行わない // debug(bs); // debug(score); // debug(solved); // hyphen(); } cout << ans << endl; }
#include<bits/stdc++.h> #define pii pair<int,int> #define ll long long using namespace std; int main() { int h,w; cin>>h>>w; int a[h+1][w+1]; for(int i=1;i<=h;i++) { for(int j=1;j<=w;j++) { char c;cin>>c; a[i][j]= c=='#'; } } int b[h][w]; for(int i=1;i<h;i++) { for(int j=1;j<w;j++) { int k=a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1]; b[i][j]= k%2==0; } } int ht[w+1]={}; int next[w+1]; int prev[w+1]; int ans=max(h,w); for(int i=1;i<h;i++) { for(int j=1;j<w;j++) ht[j]=(b[i][j]==1)? ht[j]+1: 0; ht[w]=ht[0]=-1; stack<int> st; st.push(0); for(int j=1;j<w;j++) { while(ht[st.top()]>=ht[j])st.pop(); prev[j]=st.top(); st.push(j); } while(!st.empty())st.pop(); st.push(w); for(int j=w-1;j>0;j--) { while(ht[st.top()]>=ht[j])st.pop(); next[j]=st.top(); st.push(j); } for(int j=1;j<w;j++) { ans=max(ans,(ht[j]+1)*(next[j]-prev[j])); } } cout<<ans<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (int)(n); i ++) ll INF = 1000000000; vector <int> dy = {0, 1, 0, -1}; vector <int> dx = {1, 0, -1, 0}; int main(){ int h, w; cin >> h >> w; vector <string> s(h); int black_cnt = 0; rep(i, h){ cin >> s.at(i); for(auto c: s.at(i)){ if(c == '#') black_cnt ++; } } deque <pair <int, int>> d; vector <vector<int>> dist(h, vector<int>(w, INF)); d.push_back(make_pair(0, 0)); dist.at(0).at(0) = 0; while(!d.empty()){ auto v = d.front(); d.pop_front(); int y, x; y = v.first; x = v.second; rep(i, 4){ int ny, nx; ny = y + dy.at(i); nx = x + dx.at(i); if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue; if(s.at(ny).at(nx) == '#') continue; if(dist.at(ny).at(nx) <= dist.at(y).at(x) + 1) continue; dist.at(ny).at(nx) = dist.at(y).at(x) + 1; d.push_back(make_pair(ny, nx)); } } if(dist.at(h - 1).at(w - 1) == INF){ cout << -1 << endl; return 0; } //cout << dist.at(h - 1).at(w - 1) << endl; cout << h * w - black_cnt - dist.at(h - 1).at(w - 1) - 1 << endl; }
#include<stdio.h> #include<algorithm> using namespace std; int c[100000]; int d[100000]; int main(){ int a,b; scanf("%d%d",&a,&b); for(int i=0;i<a;i++){ scanf("%d",c+i); } for(int i=0;i<b;i++){ int e; scanf("%d",&e); for(int j=0;j<a;j++){ if(e>=c[j]){ d[j]++; break; } } } int at=0; int v=0; for(int i=0;i<a;i++)if(v<d[i]){ v=d[i]; at=i; } printf("%d\n",at+1); }
0
#include <iostream> #define N 100 #define WHITE 0 #define BLACK 1 #define INF 10000 using namespace std; int M[N][N],n,d[N]; void prim(){ int color[n],p[n]; for(int i=0;i<n;i++){ color[i]=WHITE; d[i]=INF; } d[0]=0; p[0]=-1; while(1){ int mincost=INF; int u; for(int i=0;i<n;i++){ if(color[i]!=BLACK && d[i]<mincost){ mincost=d[i]; u=i; } } if(mincost==INF) break; //connect u to p[u] color[u]=BLACK; for(int v=0;v<n;v++){ if(color[v]!=BLACK && M[u][v]!=-1){ if(M[u][v]<d[v]){ d[v]=M[u][v]; p[v]=u; } } } } } int main(){ cin >> n; for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cin >> M[i][j]; } prim(); int sum=0; for(int i=0;i<n;i++) sum+=d[i]; cout << sum << endl; }
// AOJ ALDS 1_12_A #include<cstdio> #include<algorithm> #include<vector> #define rep(i,a) for( int i = 0; i != (a); ++i ) struct edge { int from, to, cost; edge( int from, int to, int cost ) : from( from ), to( to ), cost( cost ) {} }; int n; std::vector<edge> es; int par[100], rank[100]; void init() { rep( i, n ) par[i] = i, rank[i] = 0; return; } int find( int x ) { if( x == par[x] ) return x; else return par[x] = find( par[x] ); } void unite( int x, int y ) { x = find( x ); y = find( y ); if( x == y ) return; if( rank[x] < rank[y] ) par[x] = y; else { par[y] = x; if( rank[x] == rank[y] ) ++rank[x]; } return; } bool same( int x, int y ) { return find( x ) == find( y ); } int main() { scanf( "%d", &n ); rep( i, n ) { rep( j, n ) { int a; scanf( "%d", &a ); if( ~a ) es.push_back( edge( i, j, a ) ); } } std::sort( es.begin(), es.end(), []( const edge& e1, const edge& e2 ){ return e1.cost < e2.cost; } ); init(); int ans = 0; rep( i, es.size() ) { if( !same( es[i].from, es[i].to ) ) { ans += es[i].cost; unite( es[i].from, es[i].to ); } } printf( "%d\n", ans ); return 0; }
1
#include <bits/stdc++.h> #define r(i,n) for(int i=0;i<n;i++) int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; int a[22][22],h,w,mi; using namespace std; void dfs(int y,int x,int depth){ if(depth>=mi)return; r(i,4){ int y1=y,x1=x,c=0,cc=1; while(1){ if(i>1){ if(y1<0||y1>=h){c++;goto P;} if(cc&&i==2&&a[y1+1][x1]==1){c++;goto P;} if(cc&&i==3&&a[y1-1][x1]==1){c++;goto P;} if(y1+1<h&&i==2&&a[y1+1][x1])goto P; if(y1-1>=0&&i==3&&a[y1-1][x1])goto P; } else{ if(x1<0||x1>=w){c++;goto P;} if(cc&&i==0&&a[y1][x1+1]==1){c++;goto P;} if(cc&&i==1&&a[y1][x1-1]==1){c++;goto P;} if(x1+1<w&&i==0&&a[y1][x1+1])goto P; if(x1-1>=0&&i==1&&a[y1][x1-1])goto P; }y1+=dy[i];x1+=dx[i];cc=0; } P:;int y2=y1+dy[i],x2=x1+dx[i]; if(!c){if(a[y2][x2]==3||mi<depth+1){mi=depth+1;return;} else{ a[y2][x2]=0; dfs(y1,x1,depth+1); a[y2][x2]=1; }} } } int main(){ int hh,ww; while(cin>>w>>h,w){ r(i,h)r(j,w){ cin>>a[i][j]; if(a[i][j]==2){ a[i][j]=0; hh=i;mi=11; ww=j; } } dfs(hh,ww,0); if(mi==11)cout<<-1<<endl; else cout<<mi<<endl; } }
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない #include <bits/stdc++.h> #include <algorithm> //#include <cstdlib> // abs() for integer #include <cmath> // abs() for float, and fabs() #include <math.h> using namespace std; #define coYES cout << "YES" << endl #define coNO cout << "NO" << endl #define coYes cout << "Yes" << endl #define coNo cout << "No" << endl #define coyes cout << "yes" << endl #define cono cout << "no" << endl //#define cocount cout << count << endl; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) #define Cinint(n) int n;\ cin >> n; #define Cinvecint(a, n) vector<int> a(n);\ for (int i = 0; i < (int)(n); i++) {\ int num;\ cin >> num;\ a.at(i) = num;\ } #define Cinstring(s) string s;\ cin >>s; int main() { Cinint(n); Cinstring(s); int64_t count = 0; int64_t Rcount = 0; int64_t Gcount = 0; int64_t Bcount = 0; rep(i, n) { if (s.at(i) == 'R') { Rcount++; } else if (s.at(i) == 'G') { Gcount++; } else { Bcount++; } } count = Rcount*Gcount*Bcount; rep(i, n-2) { for (int j = i+1; j < n-1; j++) { int sa = j-i; int k = j+sa; if (k <= n-1) { if (s.at(i) == 'R') { if (s.at(j) == 'G') { if (s.at(k) == 'B') { count--; } } else if (s.at(j) == 'B') { if (s.at(k) == 'G') { count--; } } } else if (s.at(i) == 'G') { if (s.at(j) == 'B') { if (s.at(k) == 'R') { count--; } } else if (s.at(j) == 'R') { if (s.at(k) == 'B') { count--; } } } else { if (s.at(j) == 'R') { if (s.at(k) == 'G') { count--; } } else if (s.at(j) == 'G') { if (s.at(k) == 'R') { count--; } } } } } } cout << count << endl; }
0
#include <iostream> #include <cstdio> #include <cmath> #include <cstdio> #include <cstring> #include <string> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <algorithm> #define CH(N,A,B) (A<=N&&N<B) #define REP(i,a,b) for(int i=a;i<b;i++) #define RREP(i,a,b) for(int i=(b-1);a<=i;i--) #define F first #define S second using namespace std; int n,key[110]; string s; char alp[52] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; int main() { while(1){ cin>>n; if(n==0) break; REP(i,0,n) cin>>key[i]; cin>>s; REP(i,0,s.size()){ int pos=-1; REP(j,0,52){ if(alp[j]==s[i]){ pos = j; break; } } cout<<alp[(pos - key[i%n] + 52*10000)%52]; } cout<<endl; } return 0; }
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <functional> #include <cassert> typedef long long ll; using namespace std; #define debug(x) cerr << #x << " = " << x << endl; #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 100010 bool solve(){ int n; int k[SIZE]; char c[SIZE]; scanf("%d",&n); if(n == 0) return false; for(int i=0;i<n;i++){ scanf("%d",k+i); } scanf("%s",c); for(int i=0;c[i]!='\0';i++){ for(int j=0;j<k[i%n];j++){ if(c[i] == 'a') c[i] = 'Z'; else if(c[i] == 'A') c[i] = 'z'; else c[i]--; } } printf("%s\n",c); return true; } int main(){ while(solve()); return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, a; vector<int> an; vector<vector<int>> AN; while (cin >> n) { if (n == 0)break; for (int i = 0; i < n; i++) { cin >> a; an.push_back(a); } AN.push_back(an); an.clear(); } for (int i = 0; i < AN.size(); i++) { long long int max = 0, min = INT_MAX, MAX = 0, MIN = 0 , counter = 0, negative = 0; for (int j = 0; j < AN[i].size(); j++) { if (AN[i][j] >= 0) { max += AN[i][j]; if (MAX < max)MAX = max; counter = 1; negative = 1; } else { if (negative == 0) { if(min > abs(AN[i][j]))min=abs(AN[i][j]); } else if (counter==1){ if (AN[i][j] + max >= 0)max += AN[i][j]; else { max = 0; counter = 0; } } } } if (negative == 0)cout << -1*min << endl; else cout << MAX << endl; } return 0; }
#include <iostream> #include <algorithm> #include <vector> template <typename Iterator> auto findMaximumSum (Iterator begin , Iterator end) -> long long { long long res = * begin; auto tmp = res; for (auto ite = begin + 1; ite != end; ++ ite) { tmp += * ite; res = std::max (res , tmp); } return res; } auto main () -> int { int n; while (std::cin >> n && n) { std::vector <int> a (n); for (auto && elem : a) { std::cin >> elem; } long long ans = a [0]; for (auto ite = a.begin (); ite != a.end (); ++ ite) { auto tmp = findMaximumSum (ite , a.end ()); ans = std::max (ans , tmp); } std::cout << ans << std::endl; } }
1
#include <iostream> #include<cmath> #include<math.h> #include<algorithm> #include<fstream> #include<queue> using namespace std; void ll(){ std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(0); } int main() { ll(); priority_queue<int>pq; int arr[1000]; int n, k, sum = 0; cin >> n >> k; for (int i = 0; i<n; i++) { cin >> arr[i]; pq.push(arr[i]); } while (k--) { sum += pq.top(); pq.pop(); } cout << sum << endl; }
/** * author: otera **/ #include<iostream> #include<string> #include<cstdio> #include<cstring> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<deque> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf=1e9+7; const ll INF=1LL<<60 ; const ll mod=1e9+7 ; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(),c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } void solve() { string s; int w; cin >> s >> w; int n = (int)s.size(); for(int i = 0; i < n; i += w) { cout << s[i]; } cout << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
0
#include <bits/stdc++.h> #include <algorithm> #include<string> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int N, H, W; bool flag = false; cin >> N >> H >> W; int count = 0; for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { if (j + W - 1 <= N) { flag = true; } else { flag = false; } if (flag && i + H - 1 <= N) { ++count; } } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; int H; cin >> H; int W; cin >> W; cout << (N - H + 1) * (N - W + 1) << endl; }
1