buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #define INF (1e+9) #define LLINF (1e+18) #define LL long long using namespace std; typedef struct info { int nx; int ny; int cost; int target; info(int a, int b, int c, int d) { nx = a; ny = b; cost = c; target = d; } } info; bool isNumChar(char c) { if ((0 <= c - 48) && (c - 48 <= 9)) return true; return false; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int W, H; int N; int sx[16] = {0}; int sy[16] = {0}; char field[1024][1024] = {""}; int record[1024][1024][12] = {0}; bool flag[16] = {false}; queue<info> que; int ans; int recordReset() { for (int i = 0; i < 1024; i++) { for (int j = 0; j < 1024; j++) { for (int k = 0; k < 16; k++) { record[i][j][k] = INF; } } } } int bfs() { info now(0, 0, 0, 0); info next(0, 0, 0, 0); for (int i = 0; i < N; i++) { next = info(sx[i], sy[i], 0, i + 1); que.push(next); } recordReset(); while (!que.empty()) { now = que.front(); que.pop(); if (!flag[now.target]) { // printf("###(%d,%d):::cost<%d>:::target<%d>\n",now.nx,now.ny,now.cost,now.target); if (record[now.nx][now.ny][now.target] > now.cost) { record[now.nx][now.ny][now.target] = now.cost; if ((sx[now.target] == now.nx) && (sy[now.target] == now.ny)) { flag[now.target] = true; // printf("###target<%d> completed\n",now.target); ans += record[now.nx][now.ny][now.target]; } else { switch (field[now.nx][now.ny]) { case 'X': break; default: for (int i = 0; i < 4; i++) { next = info(now.nx + dx[i], now.ny + dy[i], now.cost + 1, now.target); que.push(next); } break; } } } } } } int main(void) { // while(true){ scanf("%d%d", &H, &W); scanf("%d", &N); // if((W == 0)&&(H == 0))break; ans = 0; // Reset Field for (int i = 0; i < 1024; i++) { for (int j = 0; j < 1024; j++) { field[j][i] = 'X'; } } // Reset Flag for (int i = 0; i < 16; i++) { flag[i] = false; } // Reading Data for (int i = 1; i <= H; i++) { scanf(" "); for (int j = 1; j <= W; j++) { scanf("%c", &field[j][i]); if (isNumChar(field[j][i])) { sx[field[j][i] - 48] = j; sy[field[j][i] - 48] = i; // printf("###<%d>(%d,%d)\n",field[j][i] - 48,sx[field[j][i] - // 48],sy[field[j][i] - 48]); } else if (field[j][i] == 'S') { sx[0] = j; sy[0] = i; // printf("###<S>(%d,%d)\n",j,i); } } } // DBG /*for(int i = 0;i < N;i++){ printf("<%d>(%d,%d)\n",i,sx[i],sy[i]); }*/ // bfs(); printf("%d\n", ans); //} return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #define INF (1e+9) #define LLINF (1e+18) #define LL long long using namespace std; typedef struct info { int nx; int ny; int cost; int target; info(int a, int b, int c, int d) { nx = a; ny = b; cost = c; target = d; } } info; bool isNumChar(char c) { if ((0 <= c - 48) && (c - 48 <= 9)) return true; return false; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int W, H; int N; int sx[16] = {0}; int sy[16] = {0}; char field[1024][1024] = {""}; int record[1024][1024][12] = {0}; bool flag[16] = {false}; queue<info> que; int ans; int recordReset() { for (int i = 0; i < 1024; i++) { for (int j = 0; j < 1024; j++) { for (int k = 0; k < 12; k++) { record[i][j][k] = INF; } } } } int bfs() { info now(0, 0, 0, 0); info next(0, 0, 0, 0); for (int i = 0; i < N; i++) { next = info(sx[i], sy[i], 0, i + 1); que.push(next); } recordReset(); while (!que.empty()) { now = que.front(); que.pop(); if (!flag[now.target]) { // printf("###(%d,%d):::cost<%d>:::target<%d>\n",now.nx,now.ny,now.cost,now.target); if (record[now.nx][now.ny][now.target] > now.cost) { record[now.nx][now.ny][now.target] = now.cost; if ((sx[now.target] == now.nx) && (sy[now.target] == now.ny)) { flag[now.target] = true; // printf("###target<%d> completed\n",now.target); ans += record[now.nx][now.ny][now.target]; } else { switch (field[now.nx][now.ny]) { case 'X': break; default: for (int i = 0; i < 4; i++) { next = info(now.nx + dx[i], now.ny + dy[i], now.cost + 1, now.target); que.push(next); } break; } } } } } } int main(void) { // while(true){ scanf("%d%d", &H, &W); scanf("%d", &N); // if((W == 0)&&(H == 0))break; ans = 0; // Reset Field for (int i = 0; i < 1024; i++) { for (int j = 0; j < 1024; j++) { field[j][i] = 'X'; } } // Reset Flag for (int i = 0; i < 16; i++) { flag[i] = false; } // Reading Data for (int i = 1; i <= H; i++) { scanf(" "); for (int j = 1; j <= W; j++) { scanf("%c", &field[j][i]); if (isNumChar(field[j][i])) { sx[field[j][i] - 48] = j; sy[field[j][i] - 48] = i; // printf("###<%d>(%d,%d)\n",field[j][i] - 48,sx[field[j][i] - // 48],sy[field[j][i] - 48]); } else if (field[j][i] == 'S') { sx[0] = j; sy[0] = i; // printf("###<S>(%d,%d)\n",j,i); } } } // DBG /*for(int i = 0;i < N;i++){ printf("<%d>(%d,%d)\n",i,sx[i],sy[i]); }*/ bfs(); printf("%d\n", ans); //} return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
846
#include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define INF (1 << 26) const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int H, W, N; cin >> H >> W >> N; vector<string> D(H); for (int i = 0; i < H; i++) cin >> D[i]; int route = 0; for (int i = 1; i <= N; i++) { queue<pair<int, int>> que; vector<vector<int>> memo(H, vector<int>(W, INF)); char start; if (i == 1) { start = 'S'; } else { start = i + 47; } pair<int, int> start_; for (int j = 0; j < H; j++) { for (int k = 0; k < W; k++) { if (D[j][k] == start) { start_.first = k; start_.second = j; } } } que.push(start_); memo[start_.second][start_.first] = route; while (que.size()) { pair<int, int> place = que.front(); que.pop(); int x, y; x = place.first; y = place.second; for (int dir = 0; dir < 4; dir++) { if (0 <= x + dx[dir] && x + dx[dir] < W && 0 <= y + dy[dir] && y + dy[dir] < H) { if (D[y + dy[dir]][x + dx[dir]] != 'X' && memo[y + dy[dir]][x + dx[dir]] == INF) { place.first = x + dx[dir]; place.second = y + dy[dir]; que.push(place); memo[y + dy[dir]][x + dx[dir]] = memo[y][x] + 1; if (D[y + dy[dir]][x + dx[dir]] - 48 == i) { route += memo[y][x] + 1; goto Exit; } } } } } Exit:; } cout << route << endl; return 0; }
#include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define INF (1 << 26) const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int H, W, N; cin >> H >> W >> N; vector<string> D(H); for (int i = 0; i < H; i++) cin >> D[i]; int route = 0; for (int i = 1; i <= N; i++) { queue<pair<int, int>> que; vector<vector<int>> memo(H, vector<int>(W, INF)); char start; if (i == 1) { start = 'S'; } else { start = i + 47; } pair<int, int> start_; for (int j = 0; j < H; j++) { for (int k = 0; k < W; k++) { if (D[j][k] == start) { start_.first = k; start_.second = j; } } } que.push(start_); memo[start_.second][start_.first] = route; while (que.size()) { pair<int, int> place = que.front(); que.pop(); int x, y; x = place.first; y = place.second; for (int dir = 0; dir < 4; dir++) { if (0 <= x + dx[dir] && x + dx[dir] < W && 0 <= y + dy[dir] && y + dy[dir] < H) { if (D[y + dy[dir]][x + dx[dir]] != 'X' && memo[y + dy[dir]][x + dx[dir]] == INF) { place.first = x + dx[dir]; place.second = y + dy[dir]; que.push(place); memo[y + dy[dir]][x + dx[dir]] = memo[y][x] + 1; if (D[y + dy[dir]][x + dx[dir]] - 48 == i) { route = memo[y][x] + 1; goto Exit; } } } } } Exit:; } cout << route << endl; return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32]]
1
526
#include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <vector> using namespace std; int main() { int n; scanf("%d", &n); vector<pair<int, pair<string, int>>> v; for (int i = 0; i < n; i++) { char pName[8]; int num; scanf("%s %d", pName, num); v.push_back(make_pair(strlen(pName), make_pair((string)pName, num))); } sort(v.begin(), v.end()); string lead = "$"; int cnt = 0; for (int i = 0; i < n; i++) { if (lead != v[i].second.first) { if (lead != "$") printf("%s %d\n", lead.c_str(), cnt); lead = v[i].second.first; cnt = v[i].second.second; } else cnt += v[i].second.second; } return (!printf("%s %d\n", lead.c_str(), cnt)); }
#include <algorithm> #include <cstdio> #include <cstring> #include <string> #include <vector> using namespace std; int main() { int n; scanf("%d", &n); vector<pair<int, pair<string, int>>> v; for (int i = 0; i < n; i++) { char pName[8]; int num; scanf("%s %d", pName, &num); v.push_back(make_pair(strlen(pName), make_pair((string)pName, num))); } sort(v.begin(), v.end()); string lead = "$"; int cnt = 0; for (int i = 0; i < n; i++) { if (lead != v[i].second.first) { if (lead != "$") printf("%s %d\n", lead.c_str(), cnt); lead = v[i].second.first; cnt = v[i].second.second; } else cnt += v[i].second.second; } return (!printf("%s %d\n", lead.c_str(), cnt)); }
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
1
244
o={} for _ in range(int(input())):p,m=input().split();o[p]=o.get(p,0)+int(m) k=sorted([(len(x),x) for x in list(o.keys())]) for i,j in k:print(i,o[j])
o={} for _ in range(int(input())):p,m=input().split();o[p]=o.get(p,0)+int(m) k=sorted([(len(x),x) for x in list(o.keys())]) for _,i in k:print(i,o[i])
[["-", 36, 36, 0, 656, 0, 7, 31, 684, 0, 22], ["+", 36, 36, 0, 656, 0, 7, 31, 684, 0, 22], ["-", 0, 1, 0, 652, 3, 4, 0, 206, 206, 22], ["+", 0, 1, 0, 652, 3, 4, 0, 206, 206, 22]]
5
89
from collections import Counter order = Counter() N = int(input()) for i in range(N): A = input().split() name,quantity = A[0],int(A[1]) order[name] += quantity po = sorted(order.items(),key=lambda x:len(x[0])) pu = sorted(po,key=lambda x:x[0]) for j,k in pu: print(j,k)
from collections import Counter order = Counter() N = int(input()) for i in range(N): A = input().split() name,quantity = A[0],int(A[1]) order[name] += quantity po = sorted(order.items(),key=lambda x:x[0]) pu = sorted(po,key=lambda x:len(x[0])) for j,k in pu: print(j,k)
[["-", 3, 4, 0, 653, 51, 670, 8, 652, 63, 22], ["-", 0, 653, 51, 670, 8, 652, 3, 4, 0, 24], ["-", 0, 653, 51, 670, 8, 652, 3, 4, 0, 25], ["+", 3, 4, 0, 653, 51, 670, 8, 652, 63, 22], ["+", 0, 653, 51, 670, 8, 652, 3, 4, 0, 24], ["+", 0, 653, 51, 670, 8, 652, 3, 4, 0, 25]]
5
108
#include <cmath> #include <iostream> using namespace std; bool is_room(int S) { for (int i = 1; 4 * i * i + i + 1 <= S; i++) if ((S - i) % (2 * i + 1) == 0) return true; return false; } int main(void) { int n, S, cnt = 0; cin >> n; while (n--) { cin >> S; if (!is_room(S)) cnt++; } cout << cnt << endl; return 0; }
#include <cmath> #include <iostream> using namespace std; bool is_room(int S) { for (int i = 1; i * i <= S; i++) if ((S - i) % (2 * i + 1) == 0) return true; return false; } int main(void) { int n, S, cnt = 0; cin >> n; while (n--) { cin >> S; if (!is_room(S)) cnt++; } cout << cnt << endl; return 0; }
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 31, 13], ["-", 31, 16, 31, 16, 31, 16, 31, 16, 17, 48], ["-", 15, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 0, 7, 15, 16, 31, 16, 31, 16, 17, 72], ["-", 8, 9, 0, 7, 15, 16, 31, 16, 17, 72], ["-", 8, 9, 0, 7, 15, 16, 31, 16, 12, 13]]
1
113
#include <iostream> using namespace std; int main() { int n, ans = 0; cin >> n; while (cin >> n) { bool ok = false; for (int y = 1; y * y < n; y++) { if ((n - y) % (2 * y + 1)) continue; ok = true; break; } ans += ok; } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int n, ans = 0; cin >> n; while (cin >> n) { bool ok = false; for (int y = 1; y * y < n; y++) { if ((n - y) % (2 * y + 1)) continue; ok = true; break; } ans += !ok; } cout << ans << endl; }
[["+", 8, 9, 0, 1, 0, 11, 12, 91, 17, 111]]
1
88
#include <iostream> using namespace std; #define loop(i, a, b) for (int i = (a); i < (int)(b); i++) #define rep(i, b) loop(i, 0, b) int main(void) { int n, S, ans = 0; cin >> n; while (n--) { cin >> S; bool ok = false; for (int i = 1; i * i <= S; i++) { if ((S - i) % (2 * i + 1) == 0) { ok = true; break; } } if (ok) ans++; } cout << ans << endl; }
#include <iostream> using namespace std; #define loop(i, a, b) for (int i = (a); i < (int)(b); i++) #define rep(i, b) loop(i, 0, b) int main(void) { int n, S, ans = 0; cin >> n; while (n--) { cin >> S; bool ok = true; for (int i = 1; i * i <= S; i++) { if ((S - i) % (2 * i + 1) == 0) { ok = false; break; } } if (ok) ans++; } cout << ans << endl; }
[["-", 0, 52, 8, 9, 0, 43, 49, 50, 51, 147], ["+", 0, 52, 8, 9, 0, 43, 49, 50, 51, 146], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 146], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 147]]
1
117
n=gets.to_i c=0 n.times{ s=gets.to_i f=true x=1 while 2*x*x+x*x<=s if (s-x)%(2*x+1)==0 f=false break end x+=1 end c+=1 if f } puts c
n=gets.to_i c=0 n.times{ s=gets.to_i f=true x=1 while 2*x*x+x+x<=s if (s-x)%(2*x+1)==0 f=false break end x+=1 end c+=1 if f } puts c
[["-", 0, 89, 15, 738, 31, 738, 12, 738, 17, 48], ["+", 8, 734, 0, 89, 15, 738, 31, 738, 17, 72]]
4
68
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, m, r; n = sc.nextInt(); m = sc.nextInt(); r = sc.nextInt(); if (r - n * m < 0) { System.out.println("0"); } BigInteger ZERO = BigInteger.ZERO; BigInteger ONE = BigInteger.ONE; BigInteger b = ONE, k; BigInteger lb = new BigInteger(Integer.toString(r - n * m)); k = new BigInteger(Integer.toString(r - n * m + n - 1)); while (k.compareTo(lb) > 0) { b = b.multiply(k); k = k.subtract(ONE); } k = new BigInteger(Integer.toString(n - 1)); while (k.compareTo(ZERO) > 0) { b = b.divide(k); k = k.subtract(ONE); } System.out.println(b); } }
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n, m, r; n = sc.nextInt(); m = sc.nextInt(); r = sc.nextInt(); if (r - n * m < 0) { System.out.println("0"); return; } BigInteger ZERO = BigInteger.ZERO; BigInteger ONE = BigInteger.ONE; BigInteger b = ONE, k; BigInteger lb = new BigInteger(Integer.toString(r - n * m)); k = new BigInteger(Integer.toString(r - n * m + n - 1)); while (k.compareTo(lb) > 0) { b = b.multiply(k); k = k.subtract(ONE); } k = new BigInteger(Integer.toString(n - 1)); while (k.compareTo(ZERO) > 0) { b = b.divide(k); k = k.subtract(ONE); } System.out.println(b); } }
[["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 8, 196, 0, 57, 64, 196, 0, 37, 0, 35]]
3
242
def fact(c) ret=1 for i in 2..c do ret*=i end return ret end a,b,r=gets.split.map(&:to_i) r=r-a*b; if r<0 then puts "0" else p fact(n+r-1)/fact(r)/fact(n-1) end
def fact(c) ret=1 for i in 2..c do ret*=i end return ret end a,b,r=gets.split.map(&:to_i) r=r-a*b m=0 if r<0 then puts "0" else p fact(a+r-1)/fact(r)/fact(a-1) end
[["-", 36, 36, 36, 36, 36, 36, 0, 493, 0, 35], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 31, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 0, 32], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 12, 612], ["-", 31, 652, 3, 4, 0, 738, 31, 738, 31, 22], ["+", 31, 652, 3, 4, 0, 738, 31, 738, 31, 22], ["-", 0, 738, 12, 652, 3, 4, 0, 738, 31, 22], ["+", 0, 738, 12, 652, 3, 4, 0, 738, 31, 22]]
4
77
n,m,r=map(int,input().split()) r-=n*m if r<0:print(0);exit(0); from math import * print(factorial(n+r-1//factorial(r))//factorial(n-1))
n,m,r=map(int,input().split()) r-=n*m if r<0:print(0);exit(0); from math import * print(factorial(n+r-1)//factorial(r)//factorial(n-1))
[["+", 0, 657, 31, 657, 31, 652, 3, 4, 0, 25], ["-", 0, 657, 12, 657, 12, 652, 3, 4, 0, 25]]
5
65
def foo(infile, outfile): import math n, m, r=infile.readline().split() n=int(n) m=int(m) r=int(r) print(0) if r-n*m >= 0: print(math.factorial(r-n*m+n-1)/math.factorial(r-n*m)/math.factorial(n-1)) else : print(0) if __name__ == "__main__": import sys foo(sys.stdin, sys.stdout)
def foo(infile, outfile): import math n, m, r=infile.readline().split() n=int(n) m=int(m) r=int(r) if r-n*m >= 0: print(math.factorial(r-n*m+n-1)/math.factorial(r-n*m)/math.factorial(n-1)) else : print(0) if __name__ == "__main__": import sys foo(sys.stdin, sys.stdout)
[["-", 0, 14, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 612], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
118
#include <math.h> #include <stdio.h> int main() { int data[5], sum = 0, i, ave; for (i = 0; i < 5; i++) { scanf("%d", &data[i]); if (data[i] < 40) { data[i] = 40; } sum = sum + data[i]; } ave = sum / 5; printf("%d\n%d\n", sum, ave); return 0; }
#include <math.h> #include <stdio.h> int main() { int data[5], sum = 0, i, ave; for (i = 0; i < 5; i++) { scanf("%d", &data[i]); if (data[i] < 40) { data[i] = 40; } sum = sum + data[i]; } ave = sum / 5; printf("%d\n", ave); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
0
102
#include <stdio.h> int main() { int a[5], sum = 0, i, ans; for (i = 0; i < 5; i++) { scanf("%d", &a[i]); if (a[i] < 40) a[i] = 40; sum += a[i]; } ans = sum / 5.0; printf("%lf\n", ans); return 0; }
#include <stdio.h> int main() { int a[5], sum = 0, i, ans; for (i = 0; i < 5; i++) { scanf("%d", &a[i]); if (a[i] < 40) a[i] = 40; sum += a[i]; } ans = sum / 5.0; printf("%d\n", ans); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
92
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int ze(int a) { if (a < 0) return -a; return a; } int main() { int a; cin >> a >> a >> a; int b, c; cin >> b >> c; int s = 0; for (int d = 0; d < a - 1; d++) { int e, f; cin >> e >> f; if ((e > b && f > c) || (e < b && d < c)) s += max(ze(e - b), ze(f - c)); else s += ze(e - b) + ze(f - c); b = e; f = c; } cout << s << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int ze(int a) { if (a < 0) return -a; return a; } int main() { int a; cin >> a >> a >> a; int b, c; cin >> b >> c; int s = 0; for (int d = 0; d < a - 1; d++) { int e, f; cin >> e >> f; if ((e > b && f > c) || (e < b && f < c)) s += max(ze(e - b), ze(f - c)); else s += ze(e - b) + ze(f - c); b = e; c = f; } cout << s << endl; }
[["-", 51, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["+", 51, 16, 12, 23, 0, 16, 12, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22]]
1
167
/* #include<iostream> #include<queue> #include<utility> using namespace std; int bfs(); const int INF = 100000000; typedef pair<int, int> P; int N, M; int sx, sy; int gx, gy; int d[100][101]; int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; int main() { cin >> N >> M; int res = bfs(); printf("%d\n", res); return 0; } int bfs() { queue<P> que; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { d[i][j] = INF; } } } */ #include <iostream> using namespace std; long W, H, N; long long huX = 1, huY = 1, ans = 0; long kaX, kaY; void kita(); void higashi(); void minami(); void nishi(); void naname(); int main() { cin >> W >> H >> N; for (int i = 0; i < N; i++) { cin >> kaX >> kaY; if (i != 0) { if (huX == kaX && huY < kaY) { kita(); } else if (huY == kaY && huX < kaX) { higashi(); } else if (huY == kaY && huX > kaX) { nishi(); } else if (huX == kaX && huY > kaY) { minami(); } else { naname(); } } if (i == 0) { huX = kaX; huY = kaY; } cout << ans << endl; } } void kita() { ans += kaY - huY; huY = kaY; huX = kaX; return; } void higashi() { ans += kaX - huX; huX = kaX; huY = kaY; return; } void minami() { ans += huY - kaY; huY = kaY; huX = kaX; return; } void nishi() { ans += huX - kaX; huY = kaY; huX = kaX; return; } void naname() { int saX, saY; saX = kaX - huX; saY = kaY - huY; if (saX == saY) { if (saX > 0) { ans += saX; } else { ans += saX * -1; } huX = kaX; huY = kaY; } else if (saX == saY * -1 || saX * -1 == saY) { if (saY > 0) { ans += saY * 2; } else { ans += saX * 2; } huX = kaX; huY = kaY; } else if (saX < saY && saX > 0 && saY > 0) { // hokuhokutou nannansei ans += saY; huX = kaX; huY = kaY; } else if (saX > saY && saX > 0 && saY > 0) { // touhokutou ans += saX; huX = kaX; huY = kaY; } else if (saX > saY && saX > 0 && saY < 0) { // tounantou ans += kaX - huX + huY - kaY; huX = kaX; huY = kaY; } else if (saX < saY && saX < 0 && saY < 0) { // seinansei ans += huX - kaX; huX = kaX; huY = kaY; } else if (saX > saY && saX < 0 && saY < 0) { ans += huY - kaY; huX = kaX; huY = kaY; } else if (saX < saY && saX < 0 && saY > 0) { // seihokusei hokuhokusei ans += huX - kaX + kaY - huY; huX = kaX; huY = kaY; } else if (saX > saY && saX > 0 && saY > 0) { // nannnantou ans += kaX - huX + huY - kaY; huX = kaX; huY = kaY; } return; }
/* #include<iostream> #include<queue> #include<utility> using namespace std; int bfs(); const int INF = 100000000; typedef pair<int, int> P; int N, M; int sx, sy; int gx, gy; int d[100][101]; int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; int main() { cin >> N >> M; int res = bfs(); printf("%d\n", res); return 0; } int bfs() { queue<P> que; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { d[i][j] = INF; } } } */ #include <iostream> using namespace std; long W, H, N; long long huX = 1, huY = 1, ans = 0; long kaX, kaY; void kita(); void higashi(); void minami(); void nishi(); void naname(); int main() { cin >> W >> H >> N; for (int i = 0; i < N; i++) { cin >> kaX >> kaY; if (i != 0) { if (huX == kaX && huY < kaY) { kita(); } else if (huY == kaY && huX < kaX) { higashi(); } else if (huY == kaY && huX > kaX) { nishi(); } else if (huX == kaX && huY > kaY) { minami(); } else { naname(); } } if (i == 0) { huX = kaX; huY = kaY; } } cout << ans << endl; } void kita() { ans += kaY - huY; huY = kaY; huX = kaX; return; } void higashi() { ans += kaX - huX; huX = kaX; huY = kaY; return; } void minami() { ans += huY - kaY; huY = kaY; huX = kaX; return; } void nishi() { ans += huX - kaX; huY = kaY; huX = kaX; return; } void naname() { int saX, saY; saX = kaX - huX; saY = kaY - huY; if (saX == saY) { if (saX > 0) { ans += saX; } else { ans += saX * -1; } huX = kaX; huY = kaY; } else if (saX == saY * -1 || saX * -1 == saY) { if (saY > 0) { ans += saY * 2; } else { ans += saX * 2; } huX = kaX; huY = kaY; } else if (saX < saY && saX > 0 && saY > 0) { // hokuhokutou nannansei ans += saY; huX = kaX; huY = kaY; } else if (saX > saY && saX > 0 && saY > 0) { // touhokutou ans += saX; huX = kaX; huY = kaY; } else if (saX > saY && saX > 0 && saY < 0) { // tounantou ans += kaX - huX + huY - kaY; huX = kaX; huY = kaY; } else if (saX < saY && saX < 0 && saY < 0) { // seinansei ans += huX - kaX; huX = kaX; huY = kaY; } else if (saX > saY && saX < 0 && saY < 0) { ans += huY - kaY; huX = kaX; huY = kaY; } else if (saX < saY && saX < 0 && saY > 0) { // seihokusei hokuhokusei ans += huX - kaX + kaY - huY; huX = kaX; huY = kaY; } else if (saX > saY && saX > 0 && saY > 0) { // nannnantou ans += kaX - huX + huY - kaY; huX = kaX; huY = kaY; } return; }
[["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46], ["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]]
1
627
int a, z, u, i, j, k, d[1999][9]; main() { scanf("%d ", &a); d[0][2] = 1; for (i = 0; i < a; i++) { u = getchar() % 4 - 1; for (j = 8; j--;) { for (k = 8; k--;) if (j & k && j >> u & 1) d[i + 1][j] += d[i][k] % 10007; u += d[a][j]; } } printf("%d\n", z % 10007); }
a, z, u, i, j, k, d[1999][9]; main() { scanf("%d ", &a); d[0][2] = 1; for (i = 0; i < a; i++) { u = getchar() % 4 - 1; for (j = 8; j--;) { for (k = 8; k--;) if (j & k && j >> u & 1) d[i + 1][j] += d[i][k] % 10007; z += d[a][j]; } } a = !printf("%d\n", z % 10007); }
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 30, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 30, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 9, 0, 1, 0, 11, 12, 91, 17, 111]]
0
148
#include <iostream> // j=前の日,1=J,11=JO,111=JOI,100=I using namespace std; int n, ho[1002] = {}, memo[112][1001][112]; char a[1002]; int sh(int j, int day, int ij) { int A = 0; A = j - ho[day]; if (A == 99 || A == 9 || A == 109 || A == 90 || A == 91 || A == -9 || A == -99 || A == -90 || A == -89) return 0; int B; B = j - ij; if (ij == 11) { if (j == 110) B = 1000; if (j == 101) B = 1000; } if (ij == 110) { if (j == 11) B = 1000; if (j == 101) B = 1000; } if (ij == 101) { if (j == 110) B = 1000; if (j == 11) B = 1000; } if (B == 9 || B == 99 || B == 109 || B == -9 || B == 90 || B == 91 || B == 89 || B == -99 || B == -90 || B == -89 || B == -109 || B == -91) { return 0; } if (day > n) return 0; if (day == n) return 1; int ans = 0; if (memo[j][day][ij] != -1) { return memo[j][day][ij]; } else { ans += sh(1, day + 1, j); ans += sh(11, day + 1, j); ans += sh(10, day + 1, j); ans += sh(100, day + 1, j); ans += sh(110, day + 1, j); ans += sh(111, day + 1, j); ans += sh(101, day + 1, j); } ans %= 10007; memo[j][day][ij] = ans; return ans; } int main() { int s[2500] = {}; cin >> n; cin >> a; ho[0] = 1; for (int i = 0; i < n; i++) { if (a[i] == 'J') ho[i + 1] = 1; if (a[i] == 'O') ho[i + 1] = 10; if (a[i] == 'I') ho[i + 1] = 100; } for (int i = 0; i < 200; i++) { for (int g = 0; g < 1200; g++) { for (int jk = 0; jk < 200; jk++) { memo[i][g][jk] = -1; } } } cout << sh(1, 0, 0) << endl; return 0; } /*#include<iostream> #include<algorithm> #include<string> #include<vector> using namespace std; string moji,yoso[200]; int f(string a) { if(moji.find(a,0)) { } int main () { int z; int ans=0; cin>>z; cin>>moji; for(int i=0;i<z;i++) { cin>>yoso[i]; } for(int i=0;i<z;i++) { if(moji.find(yoso[i],0)){ans++;continue;} f(yoso[i].at(0)); } return 0; }*/
#include <iostream> // j=前の日,1=J,11=JO,111=JOI,100=I using namespace std; int n, ho[1202] = {}, memo[112][1001][112]; char a[1202]; int sh(int j, int day, int ij) { int A = 0; A = j - ho[day]; if (A == 99 || A == 9 || A == 109 || A == 90 || A == 91 || A == -9 || A == -99 || A == -90 || A == -89) return 0; int B; B = j - ij; if (ij == 11) { if (j == 110) B = 1000; if (j == 101) B = 1000; } if (ij == 110) { if (j == 11) B = 1000; if (j == 101) B = 1000; } if (ij == 101) { if (j == 110) B = 1000; if (j == 11) B = 1000; } if (B == 9 || B == 99 || B == 109 || B == -9 || B == 90 || B == 91 || B == 89 || B == -99 || B == -90 || B == -89 || B == -109 || B == -91) { return 0; } if (day > n) return 0; if (day == n) return 1; int ans = 0; if (memo[j][day][ij] != -1) { return memo[j][day][ij]; } else { ans += sh(1, day + 1, j); ans += sh(11, day + 1, j); ans += sh(10, day + 1, j); ans += sh(100, day + 1, j); ans += sh(110, day + 1, j); ans += sh(111, day + 1, j); ans += sh(101, day + 1, j); } ans %= 10007; memo[j][day][ij] = ans; return ans; } int main() { int s[2500] = {}; cin >> n; cin >> a; ho[0] = 1; for (int i = 0; i < n; i++) { if (a[i] == 'J') ho[i + 1] = 1; if (a[i] == 'O') ho[i + 1] = 10; if (a[i] == 'I') ho[i + 1] = 100; } for (int i = 0; i < 112; i++) { for (int g = 0; g < 1001; g++) { for (int jk = 0; jk < 112; jk++) { memo[i][g][jk] = -1; } } } cout << sh(1, 0, 0) << endl; return 0; } /*#include<iostream> #include<algorithm> #include<string> #include<vector> using namespace std; string moji,yoso[200]; int f(string a) { if(moji.find(a,0)) { } int main () { int z; int ans=0; cin>>z; cin>>moji; for(int i=0;i<z;i++) { cin>>yoso[i]; } for(int i=0;i<z;i++) { if(moji.find(yoso[i],0)){ans++;continue;} f(yoso[i].at(0)); } return 0; }*/
[["-", 0, 30, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 0, 30, 0, 43, 49, 50, 49, 80, 81, 13], ["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
602
#include <iostream> #include <string> using namespace std; int n, a[1009], dp[1009][8]; string s; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == 'O') a[i] = 1; if (s[i] == 'I') a[i] = 2; } for (int i = 0; i < 8; i++) { if (i & (1 << a[0])) dp[0][i] = 1; } for (int i = 0; i < n; i++) { for (int j = 0; j < 8; j++) { if (!(j & (1 << a[i - 1]))) continue; for (int k = 0; k < 8; k++) { if (j & k) dp[i][j] += dp[i - 1][k]; } dp[i][j] %= 10007; } } int ret = 0; for (int i = 0; i < 8; i++) ret += dp[n - 1][i]; cout << ret % 10007 << endl; return 0; }
#include <iostream> #include <string> using namespace std; int n, a[1009], dp[1009][8]; string s; int main() { cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == 'O') a[i] = 1; if (s[i] == 'I') a[i] = 2; } for (int i = 1; i < 8; i += 2) { if (i & (1 << a[0])) dp[0][i] = 1; } for (int i = 1; i < n; i++) { for (int j = 0; j < 8; j++) { if (!(j & (1 << a[i]))) continue; for (int k = 0; k < 8; k++) { if (j & k) dp[i][j] += dp[i - 1][k]; } dp[i][j] %= 10007; } } int ret = 0; for (int i = 0; i < 8; i++) ret += dp[n - 1][i]; cout << ret % 10007 << endl; return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 7, 26, 27, 17, 29], ["+", 0, 14, 8, 9, 0, 7, 26, 11, 17, 107], ["+", 0, 14, 8, 9, 0, 7, 26, 11, 12, 13], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["-", 0, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
274
#include <bits/stdc++.h> using namespace std; #define pb(n) push_back(n) #define fi first #define se second #define X real() #define Y imag() #define value(x, y, w, h) (x >= 0 && x < w && y >= 0 && y < h) #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 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)) typedef long long ll; typedef deque<int> di; typedef deque<ll> dl; typedef map<string, int> dict; typedef complex<double> comd; typedef pair<int, int> pii; 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}; double CalcDist(comd p1, comd p2) { return sqrt(pow(p1.X - p2.X, 2.0) + pow(p1.Y - p2.Y, 2.0)); } template <typename T> void out(deque<T> d) { for (size_t i = 0; i < d.size(); i++) { debug(d[i]); } } template <typename T> T ston(string &str, T n) { istringstream sin(str); T num; sin >> num; return num; } int dp[9][1000]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; string s; cin >> n >> s; dp[1][0] = 1; REP(i, 1, n) { if (s[i - 1] == 'J') { rep(k, 8) { rep(j, 8) { if ((k & j) != 0 && (k & 1) != 0) { dp[k][i] = (dp[k][i] + dp[j][i - 1]) % 10007; } } } } else if (s[i - 1] == 'O') { rep(k, 8) { rep(j, 8) { if ((k & j) != 0 && (k & 2) != 0) { dp[k][i] = (dp[k][i] + dp[j][i - 1]) % 10007; } } } } else { rep(k, 8) { rep(j, 8) { if ((k & j) != 0 && (k & 4) != 0) { dp[k][i] = (dp[k][i] + dp[j][i - 1]) % 10007; } } } } } int ans = 0; rep(i, 9) { ans += dp[i][n]; } cout << ans % 10007 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb(n) push_back(n) #define fi first #define se second #define X real() #define Y imag() #define value(x, y, w, h) (x >= 0 && x < w && y >= 0 && y < h) #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 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)) typedef long long ll; typedef deque<int> di; typedef deque<ll> dl; typedef map<string, int> dict; typedef complex<double> comd; typedef pair<int, int> pii; 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}; double CalcDist(comd p1, comd p2) { return sqrt(pow(p1.X - p2.X, 2.0) + pow(p1.Y - p2.Y, 2.0)); } template <typename T> void out(deque<T> d) { for (size_t i = 0; i < d.size(); i++) { debug(d[i]); } } template <typename T> T ston(string &str, T n) { istringstream sin(str); T num; sin >> num; return num; } int dp[9][1010]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; string s; cin >> n >> s; dp[1][0] = 1; REP(i, 1, n + 1) { if (s[i - 1] == 'J') { rep(k, 8) { rep(j, 8) { if ((k & j) != 0 && (k & 1) != 0) { dp[k][i] = (dp[k][i] + dp[j][i - 1]) % 10007; } } } } else if (s[i - 1] == 'O') { rep(k, 8) { rep(j, 8) { if ((k & j) != 0 && (k & 2) != 0) { dp[k][i] = (dp[k][i] + dp[j][i - 1]) % 10007; } } } } else { rep(k, 8) { rep(j, 8) { if ((k & j) != 0 && (k & 4) != 0) { dp[k][i] = (dp[k][i] + dp[j][i - 1]) % 10007; } } } } } int ans = 0; rep(i, 9) { ans += dp[i][n]; } cout << ans % 10007 << endl; return 0; }
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
676
#include <bits/stdc++.h> using namespace std; const int N = 1e3L + 11; const int mod = 1e4L + 7; int dp[N][8]; int a[N]; int main() { ios ::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; s = '0' + s; for (int i = 1; i <= n; i++) a[i] = (s[i] == 'J') ? 1 : (s[i] == 'O') ? 2 : 4; for (int i = 0; i < 8; i++) dp[1][i] = (i & a[i]) && (i & 1); for (int i = 2; i <= n; i++) for (int j = 0; j < 8; j++) for (int k = 0; k < 8; k++) if (j & k) if (k & a[i]) { dp[i][k] += dp[i - 1][j]; dp[i][k] %= mod; } cout << accumulate(dp[n], dp[n] + 8, 0) % mod << '\n'; }
#include <bits/stdc++.h> using namespace std; const int N = 1e3L + 11; const int mod = 1e4L + 7; int dp[N][8]; int a[N]; int main() { ios ::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; s = '0' + s; for (int i = 1; i <= n; i++) a[i] = (s[i] == 'J') ? 1 : (s[i] == 'O') ? 2 : 4; for (int i = 0; i < 8; i++) dp[1][i] = (i & a[1]) && (i & 1); for (int i = 2; i <= n; i++) for (int j = 0; j < 8; j++) for (int k = 0; k < 8; k++) if (j & k) if (k & a[i]) { dp[i][k] += dp[i - 1][j]; dp[i][k] %= mod; } cout << accumulate(dp[n], dp[n] + 8, 0) % mod << '\n'; }
[["-", 31, 23, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 31, 23, 0, 16, 12, 69, 341, 342, 0, 13]]
1
268
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define MAX 100000000 #define J 100 int a[1010][2][2][2]; int main() { int n, x, y, z; string str; cin >> n >> str; if (str[0] == 'J') for (int i = 0; i < 4; i++) a[0][1][!!(i & 2)][!!(i & 1)] = 1; if (str[0] == 'O') for (int i = 0; i < 4; i++) a[0][1][1][!!(i & 1)] = 1; if (str[0] == 'I') for (int i = 0; i < 4; i++) a[0][1][!!(i & 1)][1] = 1; for (int i = 1; i < n; i++) { x = y = z = 0; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int h = 0; h < 2; h++) a[i][j][k][h] = 0; x += a[i - 1][1][j][k]; y += a[i - 1][j][1][k]; z += a[i - 1][j][k][1]; } } a[i][1][1][0] = (x + y - a[i - 1][1][1][0] - a[i - 1][1][1][1]) % 10007; a[i][1][0][1] = (x + z - a[i - 1][1][0][1] - a[i - 1][1][1][1]) % 10007; a[i][0][1][1] = (y + z - a[i - 1][0][1][1] - a[i - 1][1][1][1]) % 10007; for (int j = 0; j < 8; j++) a[i][1][1][1] += (a[i - 1][!!(j & 4)][!!(j & 2)][!!(j & 1)]) % 10007; if (str[i] == 'J') { a[i][1][0][0] = x % 10007; a[i][0][1][1] = 0; } if (str[i] == 'O') { a[i][0][1][0] = y % 10007; a[i][1][0][1] = 0; } if (str[i] == 'I') { a[i][0][0][1] = z % 10007; a[i][1][1][0] = 0; } } int ans = 0; for (int i = 0; i < 8; i++) ans += (a[n - 1][!!(i % 4)][!!(i & 2)][!!(i & 1)]); cout << ans % 10007 << endl; // for(int i = 0;i < 8;i++)cout << a[n-1][!!(i&4)][!!(i&2)][!!(i&1)] << " "; // cout << endl; // for(int i = 0;i < 8;i++)cout << !!(i&4) << !!(i&2) << !!(i&1) << " "; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; #define MAX 100000000 #define J 100 int a[1010][2][2][2]; int main() { int n, x, y, z; string str; cin >> n >> str; if (str[0] == 'J') for (int i = 0; i < 4; i++) a[0][1][!!(i & 2)][!!(i & 1)] = 1; if (str[0] == 'O') for (int i = 0; i < 4; i++) a[0][1][1][!!(i & 1)] = 1; if (str[0] == 'I') for (int i = 0; i < 4; i++) a[0][1][!!(i & 1)][1] = 1; for (int i = 1; i < n; i++) { x = y = z = 0; for (int j = 0; j < 2; j++) { for (int k = 0; k < 2; k++) { for (int h = 0; h < 2; h++) a[i][j][k][h] = 0; x += a[i - 1][1][j][k]; y += a[i - 1][j][1][k]; z += a[i - 1][j][k][1]; } } a[i][1][1][0] = (x + y - a[i - 1][1][1][0] - a[i - 1][1][1][1]) % 10007; a[i][1][0][1] = (x + z - a[i - 1][1][0][1] - a[i - 1][1][1][1]) % 10007; a[i][0][1][1] = (y + z - a[i - 1][0][1][1] - a[i - 1][1][1][1]) % 10007; for (int j = 0; j < 8; j++) a[i][1][1][1] += (a[i - 1][!!(j & 4)][!!(j & 2)][!!(j & 1)]) % 10007; if (str[i] == 'J') { a[i][1][0][0] = x % 10007; a[i][0][1][1] = 0; } if (str[i] == 'O') { a[i][0][1][0] = y % 10007; a[i][1][0][1] = 0; } if (str[i] == 'I') { a[i][0][0][1] = z % 10007; a[i][1][1][0] = 0; } } int ans = 0; for (int i = 0; i < 8; i++) ans += (a[n - 1][!!(i & 4)][!!(i & 2)][!!(i & 1)]); cout << ans % 10007 << endl; // for(int i = 0;i < 8;i++)cout << a[n-1][!!(i&4)][!!(i&2)][!!(i&1)] << " "; // cout << endl; // for(int i = 0;i < 8;i++)cout << !!(i&4) << !!(i&2) << !!(i&1) << " "; return 0; }
[["-", 0, 91, 28, 91, 28, 23, 0, 16, 17, 109], ["+", 0, 91, 28, 91, 28, 23, 0, 16, 17, 67]]
1
792
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define repi(i, a, b) for (int i = (a); i < (b); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int, int> pii; const int INF = 1 << 29; const double EPS = 1e-9; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; int dp[1050][8]; int n; const int MOD = 10007; int main() { cin >> n; dp[0][1] = 1; char c; for (int i = 1; i <= n; i++) { cin >> c; int x; if (c == 'J') { x = 0; } else if (c == 'O') { x = 1; } else { x = 2; } for (int j = 1; j < (1 << 3); j++) { //今日の状態 if ((j >> x) & 1 == 0) continue; //含んでないなら for (int k = 1; k < (1 << 3); k++) { //前日の状態 if ((j & k) == 0) continue; //含んでない dp[i][j] = (dp[i][j] + dp[i - 1][k]) % MOD; } } } int ans = 0; for (int i = 0; i < (1 << 3); i++) { ans = (ans + dp[n][i]) % MOD; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define repi(i, a, b) for (int i = (a); i < (b); i++) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int, int> pii; const int INF = 1 << 29; const double EPS = 1e-9; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; int dp[1050][8]; int n; const int MOD = 10007; int main() { cin >> n; dp[0][1] = 1; char c; for (int i = 1; i <= n; i++) { cin >> c; int x; if (c == 'J') { x = 0; } else if (c == 'O') { x = 1; } else { x = 2; } for (int j = 1; j < (1 << 3); j++) { //今日の状態 if (!(j >> x & 1)) continue; //含んでないなら for (int k = 1; k < (1 << 3); k++) { //前日の状態 if ((j & k) == 0) continue; //含んでない dp[i][j] = (dp[i][j] + dp[i - 1][k]) % MOD; } } } int ans = 0; for (int i = 0; i < (1 << 3); i++) { ans = (ans + dp[n][i]) % MOD; } cout << ans << endl; return 0; }
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["-", 0, 57, 15, 339, 51, 16, 31, 23, 0, 25], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 91, 28, 23, 0, 25]]
1
410
#include <algorithm> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define F first #define S second const int INF = 1000000000; typedef long long int lli; typedef pair<int, int> P; const int mod = 10007; int dp[1000][1 << 3]; int hoge(char c) { if (c == 'J') return 1; if (c == 'O') return 2; if (c == 'I') return 4; } int main() { int n; cin >> n; string s; cin >> s; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= 7; ++i) { if (hoge(s[0]) & i == 0 || (i & 1) == 0) continue; dp[0][i] = 1; } for (int i = 1; i < n; ++i) { for (int j = 1; j <= 7; ++j) { if ((hoge(s[i]) & j) == 0) continue; for (int k = 1; k <= 7; ++k) { if ((j & k) == 0) continue; dp[i][j] += dp[i - 1][k] % mod; } } } int ans = 0; for (int i = 1; i <= 7; ++i) { ans += dp[n - 1][i] % mod; } cout << ans % mod << "\n"; return 0; }
#include <algorithm> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define F first #define S second const int INF = 1000000000; typedef long long int lli; typedef pair<int, int> P; const int mod = 10007; int dp[1000][1 << 3]; int hoge(char c) { if (c == 'J') return 1; if (c == 'O') return 2; if (c == 'I') return 4; } int main() { int n; cin >> n; string s; cin >> s; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= 7; ++i) { if ((hoge(s[0]) & i) == 0 || (i & 1) == 0) continue; dp[0][i] = 1; } for (int i = 1; i < n; ++i) { for (int j = 1; j <= 7; ++j) { if ((hoge(s[i]) & j) == 0) continue; for (int k = 1; k <= 7; ++k) { if ((j & k) == 0) continue; dp[i][j] += dp[i - 1][k] % mod; } } } int ans = 0; for (int i = 1; i <= 7; ++i) { ans += dp[n - 1][i] % mod; } cout << ans % mod << "\n"; return 0; }
[["+", 15, 339, 51, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 339, 51, 16, 31, 16, 31, 23, 0, 25]]
1
343
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; reverse(begin(s), end(s)); int lb = 0, ub = s.size() / 3 + 10; while (ub - lb > 1) { int md = (lb + ub) / 2; int ci = 0, cio = 0, cioi = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'I') { if (ci + cio + cioi < md) ci++; else cio--, cioi++; } else if (s[i] == 'O') { if (ci > 0) ci--, cio++; } else if (s[i] == 'J') { if (cio > 0) cio--, cioi++; } } (cioi >= md ? lb : ub) = md; } cout << lb << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; reverse(begin(s), end(s)); int lb = 0, ub = s.size() / 3 + 10; while (ub - lb > 1) { int md = (lb + ub) / 2; int ci = 0, cio = 0, cioi = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'I') { if (ci + cio + cioi < md) ci++; else if (cio > 0) cio--, cioi++; } else if (s[i] == 'O') { if (ci > 0) ci--, cio++; } else if (s[i] == 'J') { if (cio > 0) cio--, cioi++; } } (cioi >= md ? lb : ub) = md; } cout << lb << endl; }
[["+", 64, 9, 0, 57, 75, 76, 0, 57, 0, 121], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 24], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 25]]
1
211
#include <iostream> #include <string> using namespace std; int n; string str; bool check(int num) { int a = 0, b = 0, c = 0; for (int i = n - 1; i > -1; --i) { if (str[i] == 'I') { if (a < num) ++a; else if (c < b) ++c; } else if (str[i] == 'O' && b < a) { ++b; } else if (c < b) ++c; } if (c >= num) return true; else return false; } int main() { cin >> n >> str; int ni = 1, na = n / 3 + 1; while (ni < na) { int nd = (ni + na) / 2; if (check(nd)) { ni = nd + 1; } else { na = nd; } } cout << na - 1 << endl; return 0; }
#include <iostream> #include <string> using namespace std; int n; string str; bool check(int num) { int a = 0, b = 0, c = 0; for (int i = n - 1; i > -1; --i) { if (str[i] == 'I') { if (a < num) ++a; else if (c < b) ++c; } else if (str[i] == 'O') { if (b < a) { ++b; } } else if (c < b) ++c; } if (c >= num) return true; else return false; } int main() { cin >> n >> str; int ni = 1, na = n / 3 + 1; while (ni < na) { int nd = (ni + na) / 2; if (check(nd)) { ni = nd + 1; } else { na = nd; } } cout << ni - 1 << endl; return 0; }
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 25], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 45], ["+", 75, 76, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 46], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22]]
1
206
#include <algorithm> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; signed main() { int a; string b; scanf("%d", &a); cin >> b; reverse(b.begin(), b.end()); // IOI???IOJ????????? int s = 0, g = a / 3 + 1; //(s,g] while (g - s > 1) { int k = (s + g) / 2; vector<int> c; for (int d = 0; d < a && c.size() < k; d++) { if (b[d] == 'I') c.push_back(d); } if (c.size() < k) { g = k; continue; } vector<int> d; int e = 0; for (int f = 0; f < k; f++) { if (c[f] > e) e = c[f] + 1; for (; g < a; g++) { if (b[g] == 'O') { d.push_back(g); g++; break; } } } if (d.size() < k) { g = k; continue; } vector<int> f; int h = 0; for (int i = 0; i < k; i++) { if (d[i] > h) h = d[i] + 1; for (; h < a; h++) { if (b[h] == 'J' || (b[h] == 'I' && h > c[k - 1])) { f.push_back(h); h++; break; } } } if (f.size() == k) { s = k; } else { g = k; } } printf("%d\n", s); }
#include <algorithm> #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; signed main() { int a; string b; scanf("%d", &a); cin >> b; reverse(b.begin(), b.end()); // IOI???IOJ????????? int s = 0, g = a / 3 + 1; //(s,g] while (g - s > 1) { int k = (s + g) / 2; vector<int> c; for (int d = 0; d < a && c.size() < k; d++) { if (b[d] == 'I') c.push_back(d); } if (c.size() < k) { g = k; continue; } vector<int> d; int e = 0; for (int f = 0; f < k; f++) { if (c[f] > e) e = c[f] + 1; for (; e < a; e++) { if (b[e] == 'O') { d.push_back(e); e++; break; } } } if (d.size() < k) { g = k; continue; } vector<int> f; int h = 0; for (int i = 0; i < k; i++) { if (d[i] > h) h = d[i] + 1; for (; h < a; h++) { if (b[h] == 'J' || (b[h] == 'I' && h > c[k - 1])) { f.push_back(h); h++; break; } } } if (f.size() == k) { s = k; } else { g = k; } } printf("%d\n", s); }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22]]
1
392
#include <stdio.h> int main(void) { int a, b, c, d; int p; int x, y; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); scanf("%d", &p); x = a * p; y = b; if (y > c) { y += (y - c) * d; } if (x < y) { printf("%d\n", x); } else { printf("%d\n", y); } return (0); }
#include <stdio.h> int main(void) { int a, b, c, d; int p; int x, y; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); scanf("%d", &p); x = a * p; y = b; if (p > c) { y += (p - c) * d; } if (x < y) { printf("%d\n", x); } else { printf("%d\n", y); } return (0); }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 31, 22]]
0
140
#include <stdio.h> int main() { int a, b, c, d, p, sum1 = 0, sum2 = 0; scanf("%d %d %d %d %d", a, b, c, d, p); sum1 = a * p; if (p > c) { sum2 = b + (p - c) * d; } else { sum2 = b; } if (sum1 < sum2) { printf("%d\n", sum1); } else { printf("%d\n", sum2); } return 0; }
#include <stdio.h> int main() { int a, b, c, d, p, sum1 = 0, sum2 = 0; scanf("%d %d %d %d %d", &a, &b, &c, &d, &p); sum1 = a * p; if (p > c) { sum2 = b + (p - c) * d; } else { sum2 = b; } if (sum1 < sum2) { printf("%d\n", sum1); } else { printf("%d\n", sum2); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67]]
0
111
#include <math.h> #include <stdio.h> int main() { int A, B, C, D, P, R; scanf("%d%d%d%d%d", &A, &B, &C, &D, &P); // printf("\n%d%d%d%d%d",A,B,C,D,P); if (P > C) { B = B + D * (P - C); } printf("%d\n%d\n%d", (int)fmin(B, A * P)); return 0; }
#include <math.h> #include <stdio.h> int main() { int A, B, C, D, P, R; scanf("%d%d%d%d%d", &A, &B, &C, &D, &P); // printf("\n%d%d%d%d%d",A,B,C,D,P); if (P > C) { B = B + D * (P - C); } printf("%d\n", (int)fmin(B, A * P)); return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
0
92
#include <stdio.h> int main() { int i, a, b, c, d, p, x, y, result; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); scanf("%d", &p); x = a * p; if (p < c) { y = b * p; } else { y = c + d * (p - c); } if (x < y) { result = x; } else { result = y; } printf("%d\n", result); return 0; }
#include <stdio.h> int main() { int i, a, b, c, d, p, x, y, result; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); scanf("%d", &p); x = a * p; if (p < c) { y = b; } else { y = b + d * (p - c); } if (x < y) { result = x; } else { result = y; } printf("%d\n", result); return 0; }
[["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
0
144
#include <stdio.h> int main(void) { int A, B, C, D, P, X = 0, Y = 0, result; scanf("%d %d %d %d %d", &A, &B, &C, &D, &P); X = A * P; if (P > C) Y = B + D * (P - C); else Y = B; if (A < B) result = Y; else result = X; printf("%d\n", result); return 0; }
#include <stdio.h> int main(void) { int A, B, C, D, P, X = 0, Y = 0, result; scanf("%d %d %d %d %d", &A, &B, &C, &D, &P); X = A * P; if (P > C) Y = B + D * (P - C); else Y = B; if (X > Y) result = Y; else result = X; printf("%d\n", result); return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 22]]
0
109
#include <stdio.h> int main() { int a, b, c, d, p, x, y; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); scanf("%d", &p); x = p * a; if (c > p) { y = b; } else if (c > p) { y = b + (p - c) * d; } if (x > y) { printf("%d\n", y); } else { printf("%d\n", x); } return 0; }
#include <stdio.h> int main() { int a, b, c, d, p, x, y; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); scanf("%d", &p); x = p * a; if (c > p) { y = b; } else if (c < p) { y = b + (p - c) * d; } if (x > y) { printf("%d\n", y); } else { printf("%d\n", x); } return 0; }
[["-", 75, 76, 0, 57, 15, 23, 0, 16, 17, 47], ["+", 75, 76, 0, 57, 15, 23, 0, 16, 17, 18]]
0
146
a; main(b, c, d, e) { scanf("%d%d%d%d%d", &a, &b, &c, &d, &e); a = !printf("%d\n", a * e < b + (e > c ? e : c) * d ? a * e : b + (e > c ? e : c) * d); }
a; main(b, c, d, e) { scanf("%d%d%d%d%d", &a, &b, &c, &d, &e); a = !printf("%d\n", a * e < b + (e > c ? e - c : 0) * d ? a * e : b + (e > c ? e - c : 0) * d); }
[["-", 12, 16, 12, 16, 31, 23, 0, 41, 0, 102], ["+", 12, 16, 31, 23, 0, 41, 64, 16, 17, 33], ["+", 12, 16, 12, 16, 31, 23, 0, 41, 0, 102], ["+", 12, 16, 12, 16, 31, 23, 0, 41, 75, 13], ["-", 75, 16, 12, 16, 31, 23, 0, 41, 0, 102], ["+", 75, 16, 12, 16, 31, 23, 0, 41, 0, 102], ["+", 75, 16, 12, 16, 31, 23, 0, 41, 75, 13]]
0
84
a; main(b, c, d, e) { scanf("%d%d%d%d%d", &a, &b, &c, &d, &e); e = e > c ? e - c : 0; a = !printf("%d\n", a * e < b + e * d ? a * e : b + e * d); }
a; main(b, c, d, e) { scanf("%d%d%d%d%d", &a, &b, &c, &d, &e); c = e > c ? e - c : 0; a = !printf("%d\n", a * e < b + c * d ? a * e : b + c * d); }
[["-", 0, 30, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 30, 0, 9, 0, 1, 0, 11, 31, 22], ["-", 0, 41, 15, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 41, 15, 16, 12, 16, 12, 16, 31, 22], ["-", 3, 4, 0, 41, 75, 16, 12, 16, 31, 22], ["+", 3, 4, 0, 41, 75, 16, 12, 16, 31, 22]]
0
80
#include <stdio.h> int main(void) { int a, b, c, d, p; int ma1, ma2; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); scanf("%d", &p); if (p > c) { ma1 = b + p * d; } else { ma1 = b; } ma2 = a * p; if (ma1 < ma2) { printf("%d\n", ma1); } else { printf("%d\n", ma2); } return 0; }
#include <stdio.h> int main(void) { int a, b, c, d, p; int ma1, ma2; scanf("%d", &a); scanf("%d", &b); scanf("%d", &c); scanf("%d", &d); scanf("%d", &p); if (p > c) { ma1 = b + (p - c) * d; } else { ma1 = b; } ma2 = a * p; if (ma1 < ma2) { printf("%d\n", ma1); } else { printf("%d\n", ma2); } return 0; }
[["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 24], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 12, 16, 31, 23, 0, 25]]
0
138
#include <bits/stdc++.h> typedef long long LL; using namespace std; int main() { int A, B, C, D, P; cin >> A >> B >> C >> D >> P; int X = A * P; int Y = B + D * max(0, C - B); cout << min(X, Y) << endl; }
#include <bits/stdc++.h> typedef long long LL; using namespace std; int main() { int A, B, C, D, P; cin >> A >> B >> C >> D >> P; int X = A * P; int Y = B + D * max(0, P - C); cout << min(X, Y) << endl; }
[["-", 12, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 12, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["-", 12, 16, 12, 2, 3, 4, 0, 16, 12, 22], ["+", 12, 16, 12, 2, 3, 4, 0, 16, 12, 22]]
1
74
#include <iostream> using namespace std; int main() { int a, b, c, d, p, n; cin >> a >> b >> c >> d >> p; n = b; if (p > c) n += (p - c) * d; cout << min(a, n) << endl; }
#include <iostream> using namespace std; int main() { int a, b, c, d, p, n; cin >> a >> b >> c >> d >> p; n = b; if (p > c) n += (p - c) * d; cout << min(a * p, n) << endl; }
[["+", 31, 16, 12, 2, 3, 4, 0, 16, 17, 48], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 12, 22]]
1
68
#include <iostream> using namespace std; int main() { int a, b, c, d, p, q, x, y; cin >> a >> b >> c >> d >> p; x = p * a; if (p <= c) { y = b; } else { y = b + (d - c) * d; } cout << (x < y ? x : y) << endl; return 0; }
#include <iostream> using namespace std; int main() { int a, b, c, d, p, q, x, y; cin >> a >> b >> c >> d >> p; x = p * a; if (p <= c) { y = b; } else { y = b + (p - c) * d; } cout << (x < y ? x : y) << endl; return 0; }
[["-", 12, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 31, 22]]
1
91
#include <iostream> using namespace std; int main() { int a, b, c, d, p; cin >> a; cin >> b; cin >> c; cin >> d; cin >> p; if (p <= c) { if (a * p < b) { cout << a * p << endl; } else { cout << b << endl; } } else { if (a * p < b + (p - c) * d) { cout << a * p << endl; } else { cout << (p - c) * d << endl; } } return 0; }
#include <iostream> using namespace std; int main() { int a, b, c, d, p; cin >> a; cin >> b; cin >> c; cin >> d; cin >> p; if (p <= c) { if (a * p < b) { cout << a * p << endl; } else { cout << b << endl; } } else { if (a * p < b + (p - c) * d) { cout << a * p << endl; } else { cout << b + (p - c) * d << endl; } } return 0; }
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72]]
1
125
#include <iostream> int main() { int a, b, c, d, p; int x = 0; int y = 0; std::cin >> a >> b >> c >> d >> p; x += a * p; y += b; if (c < p) y += (p - c) * d; if (x > y) std::cout << x << std::endl; else std::cout << y << std::endl; }
#include <iostream> int main() { int a, b, c, d, p; int x = 0; int y = 0; std::cin >> a >> b >> c >> d >> p; x += a * p; y += b; if (c < p) y += (p - c) * d; if (x > y) std::cout << y << std::endl; else std::cout << x << std::endl; }
[["-", 0, 57, 64, 1, 0, 16, 31, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 16, 31, 16, 12, 22], ["-", 75, 76, 0, 1, 0, 16, 31, 16, 12, 22], ["+", 75, 76, 0, 1, 0, 16, 31, 16, 12, 22]]
1
96
#include <bits/stdc++.h> using namespace std; int a, b, c, d, p, x, y; main() { cin >> a >> b >> c >> d >> p; x = a * p; y = max(b, (p - c) * d + b); cout << max(x, y) << endl; }
#include <bits/stdc++.h> using namespace std; int a, b, c, d, p, x, y; main() { cin >> a >> b >> c >> d >> p; x = a * p; y = max(b, (p - c) * d + b); cout << min(x, y) << endl; }
[["-", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22]]
1
72
#include <algorithm> #include <iostream> using namespace std; int main() { int A, B, C, D, P, X, Y; cin >> A >> B >> C >> D >> P; X = A * P; Y = min(B, B + D * (P - C)); cout << min(X, Y) << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int A, B, C, D, P, X, Y; cin >> A >> B >> C >> D >> P; X = A * P; Y = max(B, B + D * (P - C)); cout << min(X, Y) << endl; return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22]]
1
78
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int a, b, c, d; int p; scanf("%d%d%d%d%d", &a, &b, &c, &d, &p); if (p <= c) { printf("%d\n", min(p * a, b)); } else { printf("%d\n", min(p * a, b + (c - p) * d)); } return (0); }
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; int main() { int a, b, c, d; int p; scanf("%d%d%d%d%d", &a, &b, &c, &d, &p); if (p <= c) { printf("%d\n", min(p * a, b)); } else { printf("%d\n", min(p * a, b + (p - c) * d)); } return (0); }
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 22]]
1
108
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int a, b, c, d, p; int x, y; int main() { cin >> a >> b >> c >> d >> p; x = a * p; if (c <= p) { y = b; } else { y = b + (p - c) * d; } cout << min(x, y) << endl; return 0; }
#include <cmath> #include <cstdio> #include <iostream> using namespace std; int a, b, c, d, p; int x, y; int main() { cin >> a >> b >> c >> d >> p; x = a * p; if (p <= c) { y = b; } else { y = b + (p - c) * d; } cout << min(x, y) << endl; return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
91
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; //// < "D:\D_Download\Visual Studio ///2015\Projects\programing_contest_c++\Debug\a.txt" int main() { int A, B, C, D, P; cin >> A >> B >> C >> D >> P; int ans = A * P; int nans; if (C < P) nans = B; else nans = B + (P - C) * D; cout << min(ans, nans) << endl; return 0; }
#include "bits/stdc++.h" #include <unordered_map> #include <unordered_set> #pragma warning(disable : 4996) using namespace std; using ld = long double; template <class T> using Table = vector<vector<T>>; const ld eps = 1e-9; //// < "D:\D_Download\Visual Studio ///2015\Projects\programing_contest_c++\Debug\a.txt" int main() { int A, B, C, D, P; cin >> A >> B >> C >> D >> P; int ans = A * P; int nans; if (C > P) nans = B; else nans = B + (P - C) * D; cout << min(ans, nans) << endl; return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
120
#include <iostream> int main() { int a, b, c, d, e; std::cin >> a; std::cin >> b; std::cin >> c; std::cin >> d; std::cin >> e; int cost_a, cost_b; cost_a = a * e; if (c < e) { cost_b = b * c + (e - c) * d; } else { cost_b = b * e; } if (cost_a < cost_b) { std::cout << cost_a << std::endl; } else { std::cout << cost_b << std::endl; } return 0; }
#include <iostream> int main() { int a, b, c, d, e; std::cin >> a; std::cin >> b; std::cin >> c; std::cin >> d; std::cin >> e; int cost_a, cost_b; cost_a = a * e; if (c < e) { cost_b = b + (e - c) * d; } else { cost_b = b; } if (cost_a < cost_b) { std::cout << cost_a << std::endl; } else { std::cout << cost_b << std::endl; } return 0; }
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
1
125
#include <bits/stdc++.h> using namespace std; // #define int long long typedef long long ll; typedef pair<int, int> pii; #define ITR(v, c) for (auto v = begin(c); v != end(c); v++) #define FOR(v, a, n) for (int v = a; v < (int)(n); v++) #define FORE(x, arr) for (auto &x : arr) #define REP(v, n) FOR(v, 0, n) #define RREP(v, n) for (int v = (int)(n); v >= 0; v--) #define ALL(c) begin(c), end(c) const int DX[4] = {0, 1, 0, -1}, DY[4] = {-1, 0, 1, 0}; const int INF = 1e9; const ll INFLL = 1e18; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { ITR(i, v) os << *i << (i == end(v) - 1 ? "" : " "); return os; } //------------------------------------------------------------------------------ signed main() { int A, B, C, D, P; cin >> A >> B >> C >> D >> P; if (C >= P) cout << min(A * P, B) << endl; else cout << min(A * P, B + (P - B) * D) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #define int long long typedef long long ll; typedef pair<int, int> pii; #define ITR(v, c) for (auto v = begin(c); v != end(c); v++) #define FOR(v, a, n) for (int v = a; v < (int)(n); v++) #define FORE(x, arr) for (auto &x : arr) #define REP(v, n) FOR(v, 0, n) #define RREP(v, n) for (int v = (int)(n); v >= 0; v--) #define ALL(c) begin(c), end(c) const int DX[4] = {0, 1, 0, -1}, DY[4] = {-1, 0, 1, 0}; const int INF = 1e9; const ll INFLL = 1e18; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { ITR(i, v) os << *i << (i == end(v) - 1 ? "" : " "); return os; } //------------------------------------------------------------------------------ signed main() { int A, B, C, D, P; cin >> A >> B >> C >> D >> P; if (C >= P) cout << min(A * P, B) << endl; else cout << min(A * P, B + (P - C) * D) << endl; return 0; }
[["-", 0, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 0, 16, 12, 16, 31, 23, 0, 16, 12, 22]]
1
297
#include <cstdio> #include <iostream> using namespace std; int main() { int a, b, c, d, p, x, y; cin >> a >> b >> c >> d >> p; x = a * p; if (c <= p) { y = b; } else { p - c; y = d * (p - c) + b; } if (y < x) { cout << y << endl; } else { cout << x << endl; } return 0; }
#include <cstdio> #include <iostream> using namespace std; int main() { int a, b, c, d, p, x, y; cin >> a >> b >> c >> d >> p; x = a * p; if (p <= c) { y = b; } else { p - c; y = d * (p - c) + b; } if (y < x) { cout << y << endl; } else { cout << x << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
104
#include <iostream> using namespace std; int main() { int x, y1, y2, y3, joi; int resx, resy; cin >> x; cin >> y1; cin >> y2; cin >> y3; cin >> joi; resx = x * joi; resy = y1 + (joi > y2 ? y2 - joi : 0) * y3; cout << (resx < resy ? resx : resy) << endl; }
#include <iostream> using namespace std; int main() { int x, y1, y2, y3, joi; int resx, resy; cin >> x; cin >> y1; cin >> y2; cin >> y3; cin >> joi; resx = x * joi; resy = y1 + (joi > y2 ? joi - y2 : 0) * y3; cout << (resx < resy ? resx : resy) << endl; }
[["-", 12, 16, 31, 23, 0, 41, 64, 16, 31, 22], ["-", 12, 16, 31, 23, 0, 41, 64, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 41, 64, 16, 17, 33], ["+", 12, 16, 31, 23, 0, 41, 64, 16, 12, 22]]
1
86
#include <iostream> using namespace std; int main() { int a, b, c, d, p; int x, y; cin >> a >> b >> c >> d >> p; x = a * p; if (p > c) { y = b * p + d * (p - c); } else { y = b * p; } if (x > y) { cout << y << endl; } else { cout << x << endl; } return 0; }
#include <iostream> using namespace std; int main() { int a, b, c, d, p; int x, y; cin >> a >> b >> c >> d >> p; x = a * p; if (p > c) { y = b + d * (p - c); } else { y = b; } if (x > y) { cout << y << endl; } else { cout << x << endl; } return 0; }
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
1
103
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define MOD 1000000007 #define rep(i, n) for (i = 0; i < n; i++) #define loop(i, a, n) for (i = a; i < n; i++) #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) #define first F #define second S typedef vector<int> vi; typedef pair<int, int> pii; int main(void) { int i, j; int a, b, c, d, p; cin >> a; cin >> b; cin >> c; cin >> d; cin >> p; cout << min(p * a, max(0, b + (p - c) * d)) << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdlib.h> #include <string.h> #include <string> #include <utility> #include <vector> using namespace std; #define ll long long #define ld long double #define EPS 0.0000000001 #define INF 1e9 #define MOD 1000000007 #define rep(i, n) for (i = 0; i < n; i++) #define loop(i, a, n) for (i = a; i < n; i++) #define all(in) in.begin(), in.end() #define shosu(x) fixed << setprecision(x) #define first F #define second S typedef vector<int> vi; typedef pair<int, int> pii; int main(void) { int i, j; int a, b, c, d, p; cin >> a; cin >> b; cin >> c; cin >> d; cin >> p; cout << min(p * a, b + max(0, (p - c) * d)) << endl; }
[["+", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 17, 72], ["-", 3, 4, 0, 2, 3, 4, 0, 16, 31, 22], ["-", 3, 4, 0, 2, 3, 4, 0, 16, 17, 72]]
1
170
#include <iostream> using namespace std; int main() { int a, b, c, d, e, x, y = 0; cin >> a >> b >> c >> d >> e; if (e * a <= c) x = b; else { y = e - c; x = y * d + b; } if (e * a < x) cout << y; else cout << x; cout << endl; }
#include <iostream> using namespace std; int main() { int a, b, c, d, e, x, y = 0; cin >> a >> b >> c >> d >> e; if (e <= c) x = b; else { y = e - c; x = y * d + b; } if (e * a < x) cout << e * a; else cout << x; cout << endl; }
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 57, 64, 1, 0, 16, 12, 22], ["+", 0, 57, 64, 1, 0, 16, 12, 16, 31, 22], ["+", 0, 57, 64, 1, 0, 16, 12, 16, 17, 48], ["+", 0, 57, 64, 1, 0, 16, 12, 16, 12, 22]]
1
91
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, p; int x, y; cin >> a >> b >> c >> d >> p; x = a * p; if (c >= p) y = b; else y = b + d * p; cout << min(x, y) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, p; int x, y; cin >> a >> b >> c >> d >> p; x = a * p; if (c >= p) y = b; else y = b + d * (p - c); cout << min(x, y) << endl; }
[["+", 0, 11, 12, 16, 12, 16, 12, 23, 0, 24], ["+", 12, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 11, 12, 16, 12, 16, 12, 23, 0, 25]]
1
76
#include <iostream> using namespace std; int main() { int n, m, reason; cin >> n >> m; int tag[m], table[n] = {0}; for (int i = 0; i < m; i++) { cin >> tag[i]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> reason; if (reason == tag[i]) { table[j]++; } else { table[tag[i]]++; } } } for (int i = 0; i < n; i++) { cout << table[i] << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, m, reason; cin >> n >> m; int tag[m], table[n] = {0}; for (int i = 0; i < m; i++) { cin >> tag[i]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> reason; if (reason == tag[i]) { table[j]++; } else { table[tag[i] - 1]++; } } } for (int i = 0; i < n; i++) { cout << table[i] << endl; } return 0; }
[["+", 0, 27, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 12, 13]]
1
156
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int A[M + 1]; int answer[N + 1]; int B[M + 1][N + 1]; for (int i = 1; i < N; i++) answer[i] = 0; for (int i = 1; i <= M; i++) cin >> A[i]; for (int i = 1; i <= M; i++) { for (int j = 1; j <= N; j++) { cin >> B[i][j]; if (A[i] == B[i][j]) { answer[j]++; } else { answer[A[i]]++; } } } for (int i = 1; i <= N; i++) cout << answer[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; int A[M + 1]; int answer[N + 1]; int B[M + 1][N + 1]; for (int i = 1; i <= N; i++) answer[i] = 0; for (int i = 1; i <= M; i++) cin >> A[i]; for (int i = 1; i <= M; i++) { for (int j = 1; j <= N; j++) { cin >> B[i][j]; if (A[i] == B[i][j]) { answer[j]++; } else { answer[A[i]]++; } } } for (int i = 1; i <= N; i++) cout << answer[i] << endl; return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
1
197
N = gets.to_i M = gets.to_i A = gets.split.map(&:to_i).map{|i|i-1} sum = Array.new(N){0} M.times do |round| gets.split.map(&:to_i).map{|i|i-1}.each.with_index do |b, i| case A[round] when i sum[i] += 1 when b sum[i] += 1 else sum[A[round]] += 1 end end end p sum
N = gets.to_i M = gets.to_i A = gets.split.map(&:to_i).map{|i|i-1} sum = Array.new(N){0} M.times do |round| gets.split.map(&:to_i).map{|i|i-1}.each.with_index do |b, i| case A[round] when i sum[i] += 1 when b sum[i] += 1 else sum[A[round]] += 1 end end end puts sum
[["-", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22]]
4
114
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); char[][] weater = new char[H][W]; int[][] area = new int[H][W]; int i, j, time; for (i = 0; i < H; i++) weater[i] = sc.next().toCharArray(); for (i = 0; i < H; i++) { time = -1; for (j = 0; j < W; j++) { if (weater[i][j] == 'c') { time = 0; area[i][j] = time; time++; } else if (time >= 0) { area[i][j] = time; time++; } else if (time < 0) area[i][j] = time; } } for (i = 0; i < H; i++) { for (j = 0; j < W; j++) { if (j == W - 1) System.out.println(area[i][j]); else System.out.println(area[i][j] + " "); } } } }
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); char[][] weater = new char[H][W]; int[][] area = new int[H][W]; int i, j, time; for (i = 0; i < H; i++) weater[i] = sc.next().toCharArray(); for (i = 0; i < H; i++) { time = -1; for (j = 0; j < W; j++) { if (weater[i][j] == 'c') { time = 0; area[i][j] = time; time++; } else if (time >= 0) { area[i][j] = time; time++; } else if (time < 0) area[i][j] = time; } } for (i = 0; i < H; i++) { for (j = 0; j < W; j++) { if (j == W - 1) System.out.println(area[i][j]); else System.out.print(area[i][j] + " "); } } } }
[["-", 8, 196, 0, 57, 75, 1, 0, 492, 141, 22], ["+", 8, 196, 0, 57, 75, 1, 0, 492, 141, 22]]
3
298
import java.util.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); for (int i = 0; i < H; i++) { String line = sc.next(); int x = -1; for (int j = 1; j < W; j++) { if (line.charAt(j) == 'c') { x = 0; } else { if (x >= 0) x += 1; } if (i > 0) { System.out.print(" "); } System.out.print(x); } System.out.println(); } } }
import java.util.*; class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); for (int i = 0; i < H; i++) { String line = sc.next(); int x = -1; for (int j = 0; j < W; j++) { if (line.charAt(j) == 'c') { x = 0; } else { if (x >= 0) x += 1; } if (j > 0) { System.out.print(" "); } System.out.print(x); } System.out.println(); } } }
[["-", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["+", 8, 196, 0, 7, 502, 503, 49, 200, 51, 499], ["-", 8, 196, 0, 57, 15, 15, 0, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 31, 22]]
3
165
#include <iostream> using namespace std; int main() { int h, w; cin >> h >> w; char a[h][w]; int b[h][w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> a[i][j]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int d = 0; for (int k = j; k >= 0; k--) { if (a[i][k] == 'c') { b[i][j] = j - k; d++; break; } } if (d == 0) b[i][j] = -1; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w - 1; j++) cout << b[i][j] << " "; cout << b[i][w] << endl; } return 0; }
#include <iostream> using namespace std; int main() { int h, w; cin >> h >> w; char a[h][w]; int b[h][w]; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) cin >> a[i][j]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int d = 0; for (int k = j; k >= 0; k--) { if (a[i][k] == 'c') { b[i][j] = j - k; d++; break; } } if (d == 0) b[i][j] = -1; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w - 1; j++) cout << b[i][j] << " "; cout << b[i][w - 1] << endl; } return 0; }
[["+", 31, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 31, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
242
#include <bits/stdc++.h> using namespace std; int main() { int H, W; char S[100][101]; int Calc[100][101]; fill_n(*Calc, 100 * 101, -1); cin >> H >> W; for (int i = 0; i < H; i++) { cin >> S[i]; } for (int i = 0; i < H; i++) { for (int j = 1; j < W; j++) { if (S[i][j - 1] == 'c') Calc[i][j] = 0; else if (Calc[i][j - 1] == -1) Calc[i][j] = -1; else Calc[i][j] = Calc[i][j - 1] + 1; } } for (int i = 0; i < H; i++) { for (int j = 1; j <= W; j++) { if (j > 1) cout << " "; cout << Calc[i][j]; } cout << endl; } return (0); }
#include <bits/stdc++.h> using namespace std; int main() { int H, W; char S[100][101]; int Calc[100][101]; fill_n(*Calc, 100 * 101, -1); cin >> H >> W; for (int i = 0; i < H; i++) { cin >> S[i]; } for (int i = 0; i < H; i++) { for (int j = 1; j <= W; j++) { if (S[i][j - 1] == 'c') Calc[i][j] = 0; else if (Calc[i][j - 1] == -1) Calc[i][j] = -1; else Calc[i][j] = Calc[i][j - 1] + 1; } } for (int i = 0; i < H; i++) { for (int j = 1; j <= W; j++) { if (j > 1) cout << " "; cout << Calc[i][j]; } cout << endl; } return (0); }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 19]]
1
243
#include <iostream> using namespace std; int main() { int h, w; string s[110]; int map[110][110] = {}; cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { map[i][j] = -1; } } for (int i = 0; i < h; i++) { cin >> s[i]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == 'c') map[i][j] = 0; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (map[i][j] != -1) { if (map[i][j + 1] != 0) map[i][j + 1] = map[i][j] + 1; } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (i != j) cout << map[i][j] << " "; else cout << map[i][j]; } cout << endl; } return 0; }
#include <iostream> using namespace std; int main() { int h, w; string s[110]; int map[110][110] = {}; cin >> h >> w; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { map[i][j] = -1; } } for (int i = 0; i < h; i++) { cin >> s[i]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (s[i][j] == 'c') map[i][j] = 0; } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (map[i][j] != -1) { if (map[i][j + 1] != 0) map[i][j + 1] = map[i][j] + 1; } } } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (j != w - 1) cout << map[i][j] << " "; else cout << map[i][j]; } cout << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
312
#include <bits/stdc++.h> using namespace std; int main() { int a, b, flag; char ch; cin >> a >> b; for (int i = 0; i < a; i++) { flag = -1; for (int j = 0; j < b; j++) { scanf("%c", &ch); if (ch == 'c') { cout << '0'; flag = 0; } else { if (flag == -1) cout << flag; else cout << ++flag; } if (j != b - 1) cout << ' '; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, flag; char ch; cin >> a >> b; for (int i = 0; i < a; i++) { flag = -1; for (int j = 0; j < b; j++) { scanf(" %c", &ch); if (ch == 'c') { cout << '0'; flag = 0; } else { if (flag == -1) cout << flag; else cout << ++flag; } if (j != b - 1) cout << ' '; } cout << endl; } }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
131
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (long long i = (a); i < (b); i++) #define REP(i, N) for (long long i = 0; i < (N); i++) #define ALL(s) (s).begin(), (s).end() #define fi first #define se second #define PI acos(-1.0) #define INF 10e9 + 9 #define EPS 1e-10 #define MAX_N 100100 #define MAX_M 100100 typedef long long ll; typedef pair<ll, ll> P; typedef pair<double, double> PD; typedef pair<string, ll> PS; typedef vector<ll> V; typedef pair<P, char> PC; int h, w; char field[1000][1000]; int ans[100][100]; int main() { cin >> h >> w; REP(i, h) { REP(j, w) { cin >> field[i][j]; if (field[i][j] == 'c') ans[i][j] = 0; else ans[i][j] = -1; } } REP(i, h) { REP(j, w) { if (ans[i][j] == 0) { for (int k = j + 1; k < w; k++) { if (ans[i][k] == -1) { ans[i][k] = ans[i][k - 1] + 1; } else break; } } } } REP(i, h) { REP(j, w) { if (j == 0) cout << ans[i][j]; cout << " " << ans[i][j]; } cout << endl; } }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define FOR(i, a, b) for (long long i = (a); i < (b); i++) #define REP(i, N) for (long long i = 0; i < (N); i++) #define ALL(s) (s).begin(), (s).end() #define fi first #define se second #define PI acos(-1.0) #define INF 10e9 + 9 #define EPS 1e-10 #define MAX_N 100100 #define MAX_M 100100 typedef long long ll; typedef pair<ll, ll> P; typedef pair<double, double> PD; typedef pair<string, ll> PS; typedef vector<ll> V; typedef pair<P, char> PC; int h, w; char field[1000][1000]; int ans[100][100]; int main() { cin >> h >> w; REP(i, h) { REP(j, w) { cin >> field[i][j]; if (field[i][j] == 'c') ans[i][j] = 0; else ans[i][j] = -1; } } REP(i, h) { REP(j, w) { if (ans[i][j] == 0) { for (int k = j + 1; k < w; k++) { if (ans[i][k] == -1) { ans[i][k] = ans[i][k - 1] + 1; } else break; } } } } REP(i, h) { REP(j, w) { if (j == 0) cout << ans[i][j]; else cout << " " << ans[i][j]; } cout << endl; } }
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
1
360
#include <iostream> using namespace std; #define loop(i, n) for (int i = 1; i <= n; i++) char res[102]; int main() { int h, w; char p; cin >> h >> w; loop(i, h) { res[0] = -1; loop(j, w) { cin >> p; if (p == 'c') res[j] = 0; else if (res[j - 1] == -1) res[j] = -1; else res[j] = res[j - 1] + 1; cout << res[j]; if (j != w) cout << " "; else cout << endl; } } return 0; }
#include <iostream> using namespace std; #define loop(i, n) for (int i = 1; i <= n; i++) int res[102]; int main() { int h, w; char p; cin >> h >> w; loop(i, h) { res[0] = -1; loop(j, w) { cin >> p; if (p == 'c') res[j] = 0; else if (res[j - 1] == -1) res[j] = -1; else res[j] = res[j - 1] + 1; cout << res[j]; if (j != w) cout << " "; else cout << endl; } } return 0; }
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40]]
1
143
#include <iostream> #include <stdio.h> #include <string.h> #include <string> using namespace std; int p[100][100]; int main() { memset(p, -1, sizeof(p)); int i, j, n, m, w, h; string s; cin >> h >> w; for (i = 0; i < h; i++) { cin >> s; for (j = 0; j < w; j++) { if (s[j] == 'c') p[i][j] = 0; if (p[i][j - 1] != -1 && p[i][j] == -1 && i != 0) p[i][j] = p[i][j - 1] + 1; } } for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { cout << p[i][j]; if (j != w - 1) cout << ' '; } cout << endl; } return 0; }
#include <iostream> #include <stdio.h> #include <string.h> #include <string> using namespace std; int p[100][100]; int main() { memset(p, -1, sizeof(p)); int i, j, n, m, w, h; string s; cin >> h >> w; for (i = 0; i < h; i++) { cin >> s; for (j = 0; j < w; j++) { if (s[j] == 'c') p[i][j] = 0; if (p[i][j - 1] != -1 && p[i][j] == -1 && j != 0) p[i][j] = p[i][j - 1] + 1; } } for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { cout << p[i][j]; if (j != w - 1) cout << ' '; } cout << endl; } return 0; }
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22]]
1
225
#include <iostream> #include <string> using namespace std; int main() { int H, W; string instr; int temp; cin >> H >> W; for (int i = 0; i < H; ++i) { cin >> instr; temp = (instr[i] == '.' ? -1 : 0); cout << temp; for (int j = 1; j < W; ++j) { if (instr[j] == 'c') { temp = 0; } else if (temp == -1) { temp = -1; } else { temp = temp + 1; } cout << " " << temp; } cout << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int H, W; string instr; int temp; cin >> H >> W; for (int i = 0; i < H; ++i) { cin >> instr; temp = (instr[0] == '.' ? -1 : 0); cout << temp; for (int j = 1; j < W; ++j) { if (instr[j] == 'c') { temp = 0; } else if (temp == -1) { temp = -1; } else { temp = temp + 1; } cout << " " << temp; } cout << endl; } return 0; }
[["-", 0, 41, 15, 16, 31, 69, 341, 342, 0, 22], ["+", 0, 41, 15, 16, 31, 69, 341, 342, 0, 13]]
1
142
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, p; cin >> a >> b >> c >> d >> p; if (p > c) { b += d * (p - c); } a = a * p > b ? a * p : b; cout << a << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, d, p; cin >> a >> b >> c >> d >> p; if (p > c) { b += d * (p - c); } a = a * p < b ? a * p : b; cout << a << endl; return 0; }
[["-", 0, 1, 0, 11, 12, 41, 15, 16, 17, 47], ["+", 0, 1, 0, 11, 12, 41, 15, 16, 17, 18]]
1
76
#include <stdio.h> int main() { int a, b, c, d, p, x, y, r; scanf("%d%d%d%d%d", &a, &b, &c, &d, &p); if (c < p) { y = b; } else { y = b + (c - p) * d; } x = a * p; if (y < x) { r = y; } else { r = x; } printf("%d\n", r); return 0; }
#include <stdio.h> int main() { int a, b, c, d, p, x, y, r; scanf("%d%d%d%d%d", &a, &b, &c, &d, &p); if (c > p) { y = b; } else { y = b + (p - c) * d; } x = a * p; if (y < x) { r = y; } else { r = x; } printf("%d\n", r); return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 12, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["-", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 12, 22]]
1
112
#include <iostream> using namespace std; int main() { int a; int b, c, d; int p; int x_moni; int y_moni; int moni; cin >> a >> b >> c >> d >> p; x_moni = p * a; y_moni = b; if (p > c) { p -= c; y_moni += d * p; } moni = max(x_moni, y_moni); cout << moni << endl; return 0; }
#include <iostream> using namespace std; int main() { int a; int b, c, d; int p; int x_moni; int y_moni; int moni; cin >> a >> b >> c >> d >> p; x_moni = p * a; y_moni = b; if (p > c) { p -= c; y_moni += d * p; } moni = min(x_moni, y_moni); cout << moni << endl; return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22]]
1
92
#include <algorithm> #include <iostream> int main() { int a, b, c, d, p, A, B; std::cin >> a >> b >> c >> d >> p; A = a * p; if (p <= c) { B = c; } else { B = b + ((p - c) * d); } std::cout << std::min(A, B) << std::endl; return 0; }
#include <algorithm> #include <iostream> int main() { int a, b, c, d, p, A, B; std::cin >> a >> b >> c >> d >> p; A = a * p; if (p <= c) { B = b; } else { B = b + ((p - c) * d); } std::cout << std::min(A, B) << std::endl; return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22]]
1
94
#include <algorithm> #include <iostream> using namespace std; int main() { int A, B, C, D, P; int X, Y; cin >> A; cin >> B; cin >> C; cin >> D; cin >> P; X = A * P; if (P < C) { Y = B; } else if (C < P) { Y = (P - C) * D; } cout << min(X, Y) << endl; return (0); }
#include <algorithm> #include <iostream> using namespace std; int main() { int A, B, C, D, P; int X, Y; cin >> A; cin >> B; cin >> C; cin >> D; cin >> P; X = A * P; if (P < C) { Y = B; } else if (C < P) { Y = ((P - C) * D) + B; } cout << min(X, Y) << endl; return (0); }
[["+", 12, 16, 31, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 22]]
1
103
#include <bits/stdc++.h> using namespace std; #define llong long long #define inf 999999999 #define mp make_pair #define pb push_back #define fn fill_n typedef pair<int, int> P; typedef pair<P, int> PP; typedef pair<PP, int> PPP; typedef struct data { int now; int cost; } data; int nh[4] = {1, 0, -1, 0}; int nw[4] = {0, 1, 0, -1}; int main() { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; cout << min(a * b, c + max(0, e - c) * d) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define llong long long #define inf 999999999 #define mp make_pair #define pb push_back #define fn fill_n typedef pair<int, int> P; typedef pair<P, int> PP; typedef pair<PP, int> PPP; typedef struct data { int now; int cost; } data; int nh[4] = {1, 0, -1, 0}; int nw[4] = {0, 1, 0, -1}; int main() { int a, b, c, d, e; cin >> a >> b >> c >> d >> e; cout << min(a * e, b + max(0, e - c) * d) << endl; return 0; }
[["-", 31, 16, 12, 2, 3, 4, 0, 16, 12, 22], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 12, 22], ["-", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22]]
1
149
#include <algorithm> #include <iostream> using namespace std; int main() { int a, b, c, d, p; int sum = 0, sum_a = 0, sum_b = 0; cin >> a >> b >> c >> d >> p; sum_a = a * p; if (p <= c) sum_b = b; else if (p > c) sum_b = b + (b - c) * d; sum = min({sum_a, sum_b}); cout << sum << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int a, b, c, d, p; int sum = 0, sum_a = 0, sum_b = 0; cin >> a >> b >> c >> d >> p; sum_a = a * p; if (p <= c) sum_b = b; else if (p > c) sum_b = b + (p - c) * d; sum = min({sum_a, sum_b}); cout << sum << endl; return 0; }
[["-", 12, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 12, 16, 12, 16, 31, 23, 0, 16, 31, 22]]
1
105
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define FOR(I, A, B) for (int I = (A); I < (B); ++I) #define CLR(mat) memset(mat, 0, sizeof(mat)) typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c, d, p; cin >> a >> b >> c >> d >> p; cout << min(a, b + max(0, p - c) * d) << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define FOR(I, A, B) for (int I = (A); I < (B); ++I) #define CLR(mat) memset(mat, 0, sizeof(mat)) typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c, d, p; cin >> a >> b >> c >> d >> p; cout << min(a * p, b + max(0, p - c) * d) << endl; }
[["+", 31, 16, 12, 2, 3, 4, 0, 16, 17, 48], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 12, 22]]
1
128
A = int(input()) B = int(input()) C = int(input()) D = int(input()) P = int(input()) print(min(P*A, B if C <= P else B+(P-C)*D))
A = int(input()) B = int(input()) C = int(input()) D = int(input()) P = int(input()) print(min(P*A, B if C >= P else B+(P-C)*D))
[["-", 0, 652, 3, 4, 0, 41, 0, 666, 667, 19], ["+", 0, 652, 3, 4, 0, 41, 0, 666, 667, 20]]
5
65
import java.io.*; import java.util.StringTokenizer; class Main { static final PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = ""; while ((line = br.readLine()) != null && !line.isEmpty()) { int n = Integer.parseInt(line); int m = Integer.parseInt(br.readLine()); int[] t = new int[m]; int[] p = new int[n]; int[][] sel = new int[m][n]; StringTokenizer st1 = new StringTokenizer(br.readLine()); for (int i = 0; i < m; i++) t[i] = Integer.parseInt(st1.nextToken()); for (int i = 0; i < m; i++) { StringTokenizer st2 = new StringTokenizer(br.readLine()); for (int j = 0; j < n; j++) { sel[i][j] = Integer.parseInt(st2.nextToken()); } } for (int i = 0; i < m; i++) { int cnt = n; for (int j = 0; j < n; j++) { if (sel[i][j] == t[i]) { p[j]++; cnt--; } } p[t[i]] += cnt; } for (int i = 0; i < n; i++) out.println(p[i]); out.flush(); } } }
import java.io.*; import java.util.StringTokenizer; class Main { static final PrintWriter out = new PrintWriter(System.out); public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = ""; while ((line = br.readLine()) != null && !line.isEmpty()) { int n = Integer.parseInt(line); int m = Integer.parseInt(br.readLine()); int[] t = new int[m]; int[] p = new int[n]; int[][] sel = new int[m][n]; StringTokenizer st1 = new StringTokenizer(br.readLine()); for (int i = 0; i < m; i++) t[i] = Integer.parseInt(st1.nextToken()); for (int i = 0; i < m; i++) { StringTokenizer st2 = new StringTokenizer(br.readLine()); for (int j = 0; j < n; j++) { sel[i][j] = Integer.parseInt(st2.nextToken()); } } for (int i = 0; i < m; i++) { int cnt = n; for (int j = 0; j < n; j++) { if (sel[i][j] == t[i]) { p[j]++; cnt--; } } p[t[i] - 1] += cnt; } for (int i = 0; i < n; i++) out.println(p[i]); out.flush(); } } }
[["+", 0, 1, 0, 11, 31, 504, 71, 16, 17, 33], ["+", 0, 1, 0, 11, 31, 504, 71, 16, 12, 499]]
3
361
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO ????????????????????????????????????????????? Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] fpoint = new int[n]; int[] tage = new int[m]; int[][] who = new int[m][n]; for (int i = 0; i < m; i++) { tage[i] = sc.nextInt(); } for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { who[j][i] = sc.nextInt(); } } sc.close(); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (tage[i] == who[i][j]) { fpoint[j]++; } else { fpoint[i]++; } } } for (int i = 0; i < n; i++) { System.out.printf("%d\n", fpoint[i]); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO ????????????????????????????????????????????? Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int[] fpoint = new int[n]; int[] tage = new int[m]; int[][] who = new int[m][n]; for (int i = 0; i < m; i++) { tage[i] = sc.nextInt(); } for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { who[j][i] = sc.nextInt(); } } sc.close(); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (tage[i] == who[i][j]) { fpoint[j]++; } else { fpoint[tage[i] - 1]++; } } } for (int i = 0; i < n; i++) { System.out.printf("%d\n", fpoint[i]); // System.out.printf("%d\n", n); } } }
[["+", 0, 27, 0, 504, 71, 16, 31, 504, 516, 22], ["+", 0, 27, 0, 504, 71, 16, 31, 504, 0, 70], ["+", 0, 27, 0, 504, 71, 16, 31, 504, 0, 73], ["+", 0, 1, 0, 27, 0, 504, 71, 16, 17, 33], ["+", 0, 1, 0, 27, 0, 504, 71, 16, 12, 499]]
3
268
#include <stdio.h> int main() { int i, k, n, m, target[100], point[100], game[100][100]; scanf("%d %d", &n, &m); for (i = 0; i < m; i++) scanf("%d", &target[i]); for (i = 0; i < n; i++) point[i] = 0; for (i = 0; i < m; i++) { for (k = 0; k < n; k++) { scanf("%d", &game[i][k]); } } // ????¨? for (i = 0; i < m; i++) { for (k = 0; k < n; k++) { if (target[i] == game[i][k]) { point[k]++; } else { point[i]++; } } } for (i = 0; i < n; i++) printf("%d\n", point[i]); return 0; }
#include <stdio.h> int main() { int i, k, n, m, target[100], point[100], game[100][100]; scanf("%d %d", &n, &m); for (i = 0; i < m; i++) scanf("%d", &target[i]); for (i = 0; i < n; i++) point[i] = 0; for (i = 0; i < m; i++) { for (k = 0; k < n; k++) { scanf("%d", &game[i][k]); } } // ????¨? for (i = 0; i < m; i++) { for (k = 0; k < n; k++) { if (target[i] == game[i][k]) { point[k]++; } else { point[target[i] - 1]++; } } } for (i = 0; i < n; i++) printf("%d\n", point[i]); return 0; }
[["+", 0, 27, 28, 69, 71, 16, 31, 69, 28, 22], ["+", 0, 27, 28, 69, 71, 16, 31, 69, 0, 70], ["+", 0, 27, 28, 69, 71, 16, 31, 69, 0, 73], ["+", 0, 1, 0, 27, 28, 69, 71, 16, 17, 33], ["+", 0, 1, 0, 27, 28, 69, 71, 16, 12, 13]]
0
232
#include <stdio.h> int main(void) { int n, m, x, t; int f[101] = {}, tar[101] = {}, score[101] = {}; int i, j; scanf("%d", &n); scanf("%d", &m); for (i = 0; i < m; i++) { scanf("%d", &t); tar[i] = t; } for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf("%d", &f[j]); if (f[j] == tar[i]) score[j]++; else score[tar[i - 1]]++; } } for (i = 0; i < n; i++) printf("%d\n", score[i]); return 0; }
#include <stdio.h> int main(void) { int n, m, t; int f[101] = {}, tar[101] = {}, score[101] = {}; int i, j; scanf("%d", &n); scanf("%d", &m); for (i = 0; i < m; i++) { scanf("%d", &t); tar[i] = t; } for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf("%d", &f[j]); if (f[j] == tar[i]) score[j]++; else score[tar[i] - 1]++; } } for (i = 0; i < n; i++) printf("%d\n", score[i]); return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 27, 28, 69, 71, 16, 31, 69, 0, 73], ["-", 0, 1, 0, 27, 28, 69, 71, 69, 0, 73]]
0
202
#include <iostream> using namespace std; int n, m; int a[101], b[101][101], p[101]; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a[i]; } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { cin >> b[i][j]; } } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (a[i] == b[i][j]) { p[j] += 1; } else { p[a[j]] += 1; } } } for (int j = 1; j <= n; j++) { cout << p[j] << endl; } return 0; }
#include <iostream> using namespace std; int n, m; int a[101], b[101][101], p[101]; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> a[i]; } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { cin >> b[i][j]; } } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { if (a[i] == b[i][j]) { p[j] += 1; } else { p[a[i]] += 1; } } } for (int j = 1; j <= n; j++) { cout << p[j] << endl; } return 0; }
[["-", 31, 69, 341, 342, 0, 69, 341, 342, 0, 22], ["+", 31, 69, 341, 342, 0, 69, 341, 342, 0, 22]]
1
204
#include <iostream> using namespace std; int p[1000], a[1000], b, c, n, m; int main() { cin >> n >> m; for (int i = 0; i < m; i++) cin >> a[i]; for (int i = 0; i < m; i++) { c = 0; for (int j = 1; j <= n; j++) { cin >> b; if (a[i] == b) p[j]++; if (a[i] != b) c++; } p[a[i]] += 1 + c; } for (int i = 1; i <= n; i++) cout << p[i] << endl; return 0; }
#include <iostream> using namespace std; int p[1000], a[1000], b, c, n, m; int main() { cin >> n >> m; for (int i = 0; i < m; i++) cin >> a[i]; for (int i = 0; i < m; i++) { c = 0; for (int j = 1; j <= n; j++) { cin >> b; if (a[i] == b) p[j]++; if (a[i] != b) c++; } p[a[i]] += c; } for (int i = 1; i <= n; i++) cout << p[i] << endl; return 0; }
[["-", 8, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
1
163
#include <iostream> using namespace std; int main() { int *a_heap; int *temp; int *target; int n = 0; int m = 0; int j = 0; int i = 0; // cout << "?????°?????\????????????????????? : "; cin >> m; // cout << "?????°?????\????????????????????? : "; cin >> n; a_heap = new int[n + 1]; temp = new int[n + 1]; target = new int[n + m]; for (i = 0; i <= n; i++) { a_heap[i] = 0; temp[i] = 0; } for (i = 0; i < n + m; i++) { target[i] = 0; } // cout << "??????????????????m????±???????????????????"; for (i = 1; i <= m; i++) { cin >> target[i]; } // cout << "?????????????????£???n??????m?????\?????????????????????"; for (j = 1; j <= m; j++) { for (i = 1; i <= n; i++) { cin >> temp[i]; if (temp[i] == target[j]) { a_heap[i] += 1; } else a_heap[target[j]] += 1; } } // cout << for (j = 1; j <= n; j++) { cout << a_heap[j] << endl; } delete[] a_heap; delete[] target; delete[] temp; return 0; }
#include <iostream> using namespace std; int main() { int *a_heap; int *temp; int *target; int n = 0; int m = 0; int j = 0; int i = 0; cin >> n; // cout << "?????°?????\????????????????????? : "; cin >> m; // cout << "?????°?????\????????????????????? : "; a_heap = new int[n + 1]; temp = new int[n + 1]; target = new int[n + m]; for (i = 0; i <= n; i++) { a_heap[i] = 0; temp[i] = 0; } for (i = 0; i < n + m; i++) { target[i] = 0; } // cout << "??????????????????m????±???????????????????"; for (i = 1; i <= m; i++) { cin >> target[i]; } // cout << "?????????????????£???n??????m?????\?????????????????????"; for (j = 1; j <= m; j++) { for (i = 1; i <= n; i++) { cin >> temp[i]; if (temp[i] == target[j]) { a_heap[i] += 1; } else a_heap[target[j]] += 1; } } // cout << for (j = 1; j <= n; j++) { cout << a_heap[j] << endl; } delete[] a_heap; delete[] target; delete[] temp; return 0; }
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
1
273
#include <stdio.h> int main(void) { int N; // num int M; // kaisuu int hito[100][100]; int target[100]; int point[100] = {0}; scanf("%d", &N); scanf("%d", &M); for (int i = 0; i < M; i++) { scanf("%d", &target[i]); } for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { scanf("%d", &hito[i][j]); if (hito[i][j] == target[i]) { point[j]++; } else { point[i]++; } } } for (int i = 0; i < N; i++) { printf("%d\n", point[i]); } return 0; }
#include <stdio.h> int main(void) { int N; // num int M; // kaisuu int hito[100][100]; int target[100]; int point[100] = {0}; scanf("%d", &N); scanf("%d", &M); for (int i = 0; i < M; i++) { scanf("%d", &target[i]); } for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { scanf("%d", &hito[i][j]); if (hito[i][j] == target[i]) { point[j]++; } else { point[target[i] - 1]++; } } } for (int i = 0; i < N; i++) { printf("%d\n", point[i]); } return 0; }
[["+", 28, 69, 341, 342, 0, 16, 31, 69, 28, 22], ["+", 341, 342, 0, 16, 31, 69, 341, 342, 0, 70], ["+", 341, 342, 0, 16, 31, 69, 341, 342, 0, 73], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 12, 13]]
1
203
#include <iostream> using namespace std; int main() { int n, m, a[100]; int f[100][100]; int cnt[100]{0}; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> f[i][j]; } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (f[i][j] == a[i]) { cnt[j]++; } else { cnt[i]++; } } } for (int j = 0; j < n; j++) { cout << cnt[j] << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, m, a[100]; int f[100][100]; int cnt[100]{0}; cin >> n >> m; for (int i = 0; i < m; i++) { cin >> a[i]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { cin >> f[i][j]; } } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { if (f[i][j] == a[i]) { cnt[j]++; } else { cnt[a[i] - 1]++; } } } for (int j = 0; j < n; j++) { cout << cnt[j] << endl; } return 0; }
[["+", 28, 69, 341, 342, 0, 16, 31, 69, 28, 22], ["+", 341, 342, 0, 16, 31, 69, 341, 342, 0, 70], ["+", 341, 342, 0, 16, 31, 69, 341, 342, 0, 73], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 12, 13]]
1
203
#include <iostream> using namespace std; int main() { int N, M, i, j; int target[100], cnt[100], data[100][100]; cin >> N; cin >> M; for (i = 0; i < M; i++) { cin >> target[i]; --target[i]; } for (i = 0; i < M; i++) { for (j = 0; j < N; j++) { cin >> data[i][j]; --data[i][j]; cnt[j] = 0; } } for (j = 0; j < N; j++) { for (i = 0; i < M; i++) { if (data[i][j] == target[i]) { ++cnt[j]; } else { ++cnt[target[i]]; } } } for (j = 0; j < N; j++) { cout << cnt[j]; } }
#include <iostream> using namespace std; int main() { int N, M, i, j; int target[100], cnt[100], data[100][100]; cin >> N; cin >> M; for (i = 0; i < M; i++) { cin >> target[i]; --target[i]; } for (i = 0; i < M; i++) { for (j = 0; j < N; j++) { cin >> data[i][j]; --data[i][j]; cnt[j] = 0; } } for (j = 0; j < N; j++) { for (i = 0; i < M; i++) { if (data[i][j] == target[i]) { ++cnt[j]; } else { ++cnt[target[i]]; } } } for (j = 0; j < N; j++) { cout << cnt[j] << endl; } }
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
219
#include <iostream> int main(int argc, char **argv) { int n, m; int score[100] = {}; int target[100]; std::cin >> n >> m; for (int i = 0; i < m; i++) { std::cin >> target[i]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { int input; std::cin >> input; /*if(j == target[i]){ score[j]++; }else */ if (input == target[i]) { score[j]++; } else { score[target[i]]++; } } } for (int i = 0; i < n; i++) { std::cout << score[i] << std::endl; } return 0; }
#include <iostream> int main(int argc, char **argv) { int n, m; int score[100] = {}; int target[100]; std::cin >> n >> m; for (int i = 0; i < m; i++) { std::cin >> target[i]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { int input; std::cin >> input; if (input == target[i]) { score[j]++; } else { score[target[i] - 1]++; } } } for (int i = 0; i < n; i++) { std::cout << score[i] << std::endl; } return 0; }
[["+", 0, 27, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 27, 28, 69, 341, 342, 0, 16, 12, 13]]
1
171
#include <algorithm> #include <stdio.h> #include <vector> using namespace std; int main(void) { int h, w, c; char t; scanf("%d %d", &h, &w); for (int j = 0; j < h; ++j) { getchar(); c = -2; for (int i = 0; i < w; ++i) { scanf("%c", &t); if (t == 'c') c = -1; if (c == -2) { if (i == w - 1) { printf("-1\n"); } else { printf("-1 "); } } else { if (i == w - 1) { printf("%d\n", ++c); } else { printf("%d ", ++c); } } } printf("\n"); } }
#include <algorithm> #include <stdio.h> #include <vector> using namespace std; int main(void) { int h, w, c; char t; scanf("%d %d", &h, &w); for (int j = 0; j < h; ++j) { getchar(); c = -2; for (int i = 0; i < w; ++i) { scanf("%c", &t); if (t == 'c') c = -1; if (c == -2) { if (i == w - 1) { printf("-1\n"); } else { printf("-1 "); } } else { if (i == w - 1) { printf("%d\n", ++c); } else { printf("%d ", ++c); } } } } }
[["-", 0, 7, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 62], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35]]
1
182
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int main(int argc, char *argv[]) { int H, W; cin >> H >> W; cin.ignore(); char grid[H][W]; int ans[H][W]; for (int y = 0; y < H; ++y) { string str; getline(cin, str); for (int x = 0; x < W; ++x) { grid[y][x] = str[x]; ans[y][x] = -1; } } for (int t = 0; t < W; ++t) { // move for (int y = 0; y < H; ++y) { for (int x = W - 2; x >= 0; --x) { if (t > 0) { grid[y][x + 1] = grid[y][x]; grid[y][x] = '.'; } } } // check for (int y = 0; y < H; ++y) { for (int x = 0; x < W; ++x) { if (grid[y][x] == 'c' && grid[y][x] == -1) { ans[y][x] = t; } } } } for (int y = 0; y < H; ++y) { bool first = true; for (int x = 0; x < W; ++x) { if (first) { cout << ans[y][x]; first = false; } else cout << " " << ans[y][x]; } cout << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int main(int argc, char *argv[]) { int H, W; cin >> H >> W; cin.ignore(); char grid[H][W]; int ans[H][W]; for (int y = 0; y < H; ++y) { string str; getline(cin, str); for (int x = 0; x < W; ++x) { grid[y][x] = str[x]; ans[y][x] = -1; } } for (int t = 0; t < W; ++t) { // move for (int y = 0; y < H; ++y) { for (int x = W - 2; x >= 0; --x) { if (t > 0) { grid[y][x + 1] = grid[y][x]; grid[y][x] = '.'; } } } // check for (int y = 0; y < H; ++y) { for (int x = 0; x < W; ++x) { if (grid[y][x] == 'c' && ans[y][x] == -1) { ans[y][x] = t; } } } } for (int y = 0; y < H; ++y) { bool first = true; for (int x = 0; x < W; ++x) { if (first) { cout << ans[y][x]; first = false; } else cout << " " << ans[y][x]; } cout << endl; } return 0; }
[["-", 51, 16, 12, 16, 31, 69, 28, 69, 28, 22], ["+", 51, 16, 12, 16, 31, 69, 28, 69, 28, 22]]
1
371
import java.util.*; class Main { static Scanner scan = new Scanner(System.in); public static void main(String[] args) { int n = scan.nextInt(); int m = scan.nextInt(); int[] dist = new int[n]; int[] weather = new int[m]; int[][] dp = new int[n + 1][m + 1]; for (int i = 0; i < n; i++) { dist[i] = scan.nextInt(); } for (int i = 0; i < m; i++) { weather[i] = scan.nextInt(); } for (int i = 1; i <= n; i++) { for (int j = 0; j <= m; j++) { dp[i][j] = 2100000000; } } solve(dist, weather, dp); int min = 2100000000; for (int i = 0; i < m; i++) { if (min > dp[n][i]) { min = dp[n][i]; } } System.out.println(min); /* for (int i = 0; i < n+1; i++) { for (int j = 0; j < m+1; j++) { System.out.print(dp[i][j] + " "); } System.out.println(" "); } */ } public static void solve(int dist[], int weather[], int dp[][]) { for (int i = 1; i <= dist.length; i++) { for (int j = i; j <= weather.length - dist.length + i; j++) { for (int k = i - 1; k < j; k++) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + (dist[i - 1] * weather[j - 1])); } } } } public static int min(int a, int b) { if (a < b) { return a; } else { return b; } } }
import java.util.*; class Main { static Scanner scan = new Scanner(System.in); public static void main(String[] args) { int n = scan.nextInt(); int m = scan.nextInt(); int[] dist = new int[n]; int[] weather = new int[m]; int[][] dp = new int[n + 1][m + 1]; for (int i = 0; i < n; i++) { dist[i] = scan.nextInt(); } for (int i = 0; i < m; i++) { weather[i] = scan.nextInt(); } for (int i = 1; i <= n; i++) { for (int j = 0; j <= m; j++) { dp[i][j] = 2100000000; } } solve(dist, weather, dp); int min = 2100000000; for (int i = 0; i <= m; i++) { if (min > dp[n][i]) { min = dp[n][i]; } } System.out.println(min); /* for (int i = 0; i < n+1; i++) { for (int j = 0; j < m+1; j++) { System.out.print(dp[i][j] + " "); } System.out.println(" "); } */ } public static void solve(int dist[], int weather[], int dp[][]) { for (int i = 1; i <= dist.length; i++) { for (int j = i; j <= weather.length - dist.length + i; j++) { for (int k = i - 1; k < j; k++) { dp[i][j] = min(dp[i][j], dp[i - 1][k] + (dist[i - 1] * weather[j - 1])); } } } } public static int min(int a, int b) { if (a < b) { return a; } else { return b; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19]]
3
414
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <utility> using namespace std; typedef long long LL; typedef pair<int, int> P; typedef queue<P> Q; #define _CRT_SECURE_NO_WARNINGS const int INF = 2001001001; int N, M = 0; int a[1005]; int d[1005]; int c[1005] = {}; int dp[1005][1005]; // place/day int main() { cin >> N >> M; for (int i = 1; i <= N; i++) { cin >> d[i]; } for (int i = 1; i <= M; i++) { cin >> c[i]; } for (int i = 0; i <= N; i++) { for (int j = 0; j <= M; j++) { dp[i][j] = INF; if (i == 0) { dp[0][j] = 0; } } } for (int j = 2; j <= M; j++) { // day for (int i = 1; i <= N; i++) { // place dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + c[j - 1] * d[i]); } } int ans = INF; for (int j = 1; j <= M; j++) { // day ans = min(dp[N][j], ans); } cout << ans << endl; return 0; }
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <string.h> #include <string> #include <utility> using namespace std; typedef long long LL; typedef pair<int, int> P; typedef queue<P> Q; #define _CRT_SECURE_NO_WARNINGS const int INF = 2001001001; int N, M = 0; int a[1005]; int d[1005]; int c[1005] = {}; int dp[1005][1005]; // place/day int main() { cin >> N >> M; for (int i = 1; i <= N; i++) { cin >> d[i]; } for (int i = 1; i <= M; i++) { cin >> c[i]; } for (int i = 0; i <= N; i++) { for (int j = 0; j <= M; j++) { dp[i][j] = INF; if (i == 0) { dp[0][j] = 0; } } } for (int j = 1; j <= M; j++) { // day for (int i = 1; i <= N; i++) { // place dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + c[j] * d[i]); } } int ans = INF; for (int j = 1; j <= M; j++) { // day ans = min(dp[N][j], ans); } cout << ans << endl; return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["-", 12, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
1
336
#include <iostream> #include <vector> using namespace std; int n, m, an = 1e9; int d[1002]; int c[1002]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> d[i]; for (int i = 0; i < m; i++) cin >> c[i]; vector<vector<int>> vec(m + 2, vector<int>(n + 1e9)); vec[0][0] = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { vec[i + 1][j] = min(vec[i + 1][j], vec[i][j]); vec[i + 1][j + 1] = min(vec[i + 1][j + 1], vec[i][j] + c[i] * d[j]); } } for (int i = 0; i <= m; i++) an = min(an, vec[i][n]); cout << an << endl; }
#include <iostream> #include <vector> using namespace std; int n, m, an = 1e9; int d[1002]; int c[1002]; int main() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> d[i]; for (int i = 0; i < m; i++) cin >> c[i]; vector<vector<int>> vec(m + 2, vector<int>(n + 2, 1e9)); vec[0][0] = 0; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { vec[i + 1][j] = min(vec[i + 1][j], vec[i][j]); vec[i + 1][j + 1] = min(vec[i + 1][j + 1], vec[i][j] + c[i] * d[j]); } } for (int i = 0; i <= m; i++) an = min(an, vec[i][n]); cout << an << endl; }
[["+", 51, 4, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 49, 50, 51, 4, 0, 2, 3, 4, 0, 21]]
1
260
#include <iostream> using namespace std; int main() { int n, m, a = 1e9; int d[1000]; int c[1000]; int dp[1002][1002]; cin >> n >> m; for (int i = 0; i <= m; i++) for (int j = 0; j <= n; j++) dp[i][j] = 1e9; for (int i = 0; i <= m; i++) dp[i][0] = 0; for (int i = 0; i < n; i++) cin >> d[i]; for (int i = 0; i < m; i++) cin >> c[i]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + c[i] * d[i]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } for (int i = 1; i <= m; i++) a = min(a, dp[i][n]); cout << a << endl; }
#include <iostream> using namespace std; int main() { int n, m, a = 1e9; int d[1000]; int c[1000]; int dp[1002][1002]; cin >> n >> m; for (int i = 0; i <= m; i++) for (int j = 0; j <= n; j++) dp[i][j] = 1e9; for (int i = 0; i <= m; i++) dp[i][0] = 0; for (int i = 0; i < n; i++) cin >> d[i]; for (int i = 0; i < m; i++) cin >> c[i]; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + c[i] * d[j]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } for (int i = 1; i <= m; i++) a = min(a, dp[i][n]); cout << a << endl; }
[["-", 0, 16, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 16, 12, 16, 12, 69, 341, 342, 0, 22]]
1
295
#include <iostream> using namespace std; #define re(i, n) for (int i = 0; i < n; i++) #define m(a, b) a = min(a, b) int main() { int n, m, a = 1e9, c[1000], d[1000], dp[1002][1002]; cin >> n >> m; re(i, m + 1) re(j, n + 1) dp[i][j] = 1e9; dp[0][0] = 0; re(i, n) cin >> d[i]; re(i, m) cin >> c[i]; re(i, m) { re(j, n) { m(dp[i + 1][j + 1], dp[i][j] + c[i] * d[j]); m(dp[i + 1][j], dp[i][j]); } } re(i, m) m(a, dp[i][n]); cout << a << endl; }
#include <iostream> using namespace std; #define re(i, n) for (int i = 0; i < n; i++) #define m(a, b) a = min(a, b) int main() { int n, m, a = 1e9, c[1000], d[1000], dp[1002][1002]; cin >> n >> m; re(i, m + 1) re(j, n + 1) dp[i][j] = 1e9; dp[0][0] = 0; re(i, n) cin >> d[i]; re(i, m) cin >> c[i]; re(i, m) { re(j, n) { m(dp[i + 1][j + 1], dp[i][j] + c[i] * d[j]); m(dp[i + 1][j], dp[i][j]); } } re(i, m + 1) m(a, dp[i][n]); cout << a << endl; }
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13]]
1
222
#include <algorithm> #include <stdio.h> using namespace std; #define max 10000000 int main() { int m, n; int dp[10000][10000], dis[10000], weather[10000]; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &dis[i]); } for (int j = 1; j <= m; j++) { scanf("%d", &weather[j]); } for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i <= m - n && j == 0) { dp[i][j] = 0; } else if (i < j) { dp[i][j] = max; } else if (i - j >= n) { dp[i][j] = max; } } } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + weather[i] * dis[j]); } } printf("%d\n", dp[m][n]); return 0; }
#include <algorithm> #include <stdio.h> using namespace std; #define max 1000000000 int main() { int m, n; int dp[1100][1100], dis[1100], weather[1100]; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &dis[i]); } for (int j = 1; j <= m; j++) { scanf("%d", &weather[j]); } for (int i = 0; i <= m; i++) { for (int j = 0; j <= n; j++) { if (i <= m - n && j == 0) { dp[i][j] = 0; } else if (i < j) { dp[i][j] = max; } else if (i - j >= n) { dp[i][j] = max; } } } for (int i = 1; i <= m; i++) { for (int j = 1; j <= n; j++) { dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - 1] + weather[i] * dis[j]); } } printf("%d\n", dp[m][n]); return 0; }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["-", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 80, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
1
302
#include <algorithm> #include <cstring> #include <iostream> using namespace std; #define MAX_N 3000 #define MAX_M 3000 int main() { int dp[MAX_N + 1][MAX_M + 1]; int n, m, s, x[MAX_N], y[MAX_M]; memset(dp, 127, sizeof(dp)); memset(x, 127, sizeof(x)); memset(y, 127, sizeof(y)); cin >> m >> n; for (int i = 1; i <= m; i++) { cin >> x[i]; } for (int i = 1; i <= n; i++) { cin >> y[i]; } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + x[j + 1] * y[i + 1]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } cout << dp[n][m] << endl; return 0; }
#include <algorithm> #include <cstring> #include <iostream> using namespace std; #define MAX_N 1100 #define MAX_M 1100 int main() { int dp[MAX_N + 1][MAX_M + 1]; int n, m, s, x[MAX_N], y[MAX_M]; memset(dp, 127, sizeof(dp)); memset(x, 127, sizeof(x)); memset(y, 127, sizeof(y)); cin >> m >> n; for (int i = 1; i <= m; i++) { cin >> x[i]; } for (int i = 1; i <= n; i++) { cin >> y[i]; } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + x[j + 1] * y[i + 1]); dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); } } cout << dp[n][m] << endl; return 0; }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
1
277
#include <cstdio> #define k 1024 #define r(a) for (int i = 0; i < a; i++) #define s(a) scanf("%d", &a); #define m(a, b) a < b ? a : b int w, n, m, c[k], d[k], p[k]; main() { s(n) s(m) r(n) s(d[i]) r(m) s(c[i]) r(n + 1) p[i] = 1e9; r(m * n) w = n - i % n, p[w] = m(p[w], p[w - 1] + c[i / n] * d[w - 1]); printf("%d\n", p[n]); }
#include <cstdio> #define k 1024 #define r(a) for (int i = 0; i < a; i++) #define s(a) scanf("%d", &a); #define m(a, b) a < b ? a : b int w, n, m, c[k], d[k], p[k]; main() { s(n) s(m) r(n) s(d[i]) r(m) s(c[i]) r(n) p[i + 1] = 1e9; r(m * n) w = n - i % n, p[w] = m(p[w], p[w - 1] + c[i / n] * d[w - 1]); printf("%d\n", p[n]); }
[["-", 0, 42, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 42, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 0, 11, 31, 69, 341, 342, 0, 16, 17, 72], ["+", 0, 11, 31, 69, 341, 342, 0, 16, 12, 13]]
1
156
#include <cstdio> #define k 1024 #define r(a) for (int i = 0; ++i < a;) #define s(a) scanf("%d", a); #define m(a, b) a < b ? a : b int w, n, m, c[k], d[k], p[k]; main() { s(&n) s(&m) r(n) s(d + i) r(m) s(c + i) r(n) p[i + 1] = 1e9; r(m * n) w = n - i % n, p[w] = m(p[w], p[w - 1] + c[i / n] * d[w - 1]); printf("%d\n", p[n]); }
#import <cstdio> #define k 1024 #define r(a) for (int i = 0; i < a; i++) #define s(a) scanf("%d", a); #define m(a, b) a < b ? a : b int w, n, m, c[k], d[k], p[k]; main() { s(&n) s(&m) r(n) s(d + i) r(m) s(c + i) r(n) p[i + 1] = 1e9; r(m * n) w = n - i % n, p[w] = m(p[w], p[w - 1] + c[i / n] * d[w - 1]); printf("%d\n", p[n]); }
[["-", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["+", 36, 36, 36, 36, 0, 30, 0, 181, 182, 183], ["-", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 112, 51, 59]]
1
156
#import <cstdio> #define r(a) for (int i = 0; i < a; i++) #define s scanf("%d", &w), w; #define c(a, b) a = a < b ? a : b int w, n, m, d[999], p[999]; main() { n = s m = s r(n) d[i] = s r(n) p[i] = 1e9; r(m) { s r(n) c(p[i], p[i + 1] + w * d[n - i - 1]); } printf("%d\n", *p); }
#import <cstdio> #define r(a) for (int i = 0; i < a; i++) #define s (scanf("%d", &w), w); #define c(a, b) a = a < b ? a : b int w, n, m, d[999], p[999]; main() { n = s m = s r(n) d[i] = s r(n) p[i] = 1e9; r(m) { s r(n) c(p[i], p[i + 1] + w * d[n - i - 1]); } printf("%d\n", *p); }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
1
116