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 <stdio.h> #define N 50 int main(void) { int n, r; int c[N]; int deck_A[N], deck_B[N], deck_C[N]; int i, j, k; int len; int last; // input the number of cards n and the number of operations r while (scanf("%d%d", &n, &r) != EOF) { // input each operation c for (i = 0; i != r; ++i) { scanf("%d", c + i); } // init the deck for (i = 0; i != n; ++i) { deck_C[i] = i; } // riffle shuffle for (i = 0; i != r; ++i) { // divide cards into deck A and deck B // deck A consists of the top half, and deck B of the bottom half len = n / 2; for (j = 0; j != len; ++j) { deck_B[j] = deck_C[j]; } for (k = 0; j != n; ++k, ++j) { deck_A[k] = deck_C[j]; } // operate len = n / 2 - n / 2 % c[i]; // j is index of deck A and B,k is index of deck C for (j = 0, k = 0; j != len; ++j) { deck_C[k] = deck_A[j]; deck_C[k + c[i]] = deck_B[j]; k += (j + 1) % c[i] == 0 ? 1 + c[i] : 1; } len = 1 + n / 2; last = j; for (; j != len; ++j, ++k) { deck_C[k] = deck_A[j]; } len = n / 2; for (j = last; j != len; ++j, ++k) { deck_C[k] = deck_B[j]; } } printf("%d\n", deck_C[n - 1]); } return 0; }
#include <stdio.h> #define N 50 int main(void) { int n, r; int c[N]; int deck_A[N], deck_B[N], deck_C[N]; int i, j, k; int len; int last; // input the number of cards n and the number of operations r while (scanf("%d%d", &n, &r) != EOF) { // input each operation c for (i = 0; i != r; ++i) { scanf("%d", &c[i]); } // init the deck for (i = 0; i != n; ++i) { deck_C[i] = i; } // riffle shuffle for (i = 0; i != r; ++i) { // divide cards into deck A and deck B // deck A consists of the top half, and deck B of the bottom half len = n / 2; for (j = 0; j != len; ++j) { deck_B[j] = deck_C[j]; } for (k = 0; j != n; ++k, ++j) { deck_A[k] = deck_C[j]; } // operate len = n / 2 - n / 2 % c[i]; // j is index of deck A and B,k is index of deck C for (j = 0, k = 0; j != len; ++j) { deck_C[k] = deck_A[j]; deck_C[k + c[i]] = deck_B[j]; k += (j + 1) % c[i] == 0 ? 1 + c[i] : 1; } len = (1 + n) / 2; last = j; for (; j != len; ++j, ++k) { deck_C[k] = deck_A[j]; } len = n / 2; for (j = last; j != len; ++j, ++k) { deck_C[k] = deck_B[j]; } } printf("%d\n", deck_C[n - 1]); } return 0; }
[["+", 0, 1, 0, 2, 3, 4, 0, 66, 17, 67], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 2, 3, 4, 0, 66, 28, 69, 0, 70], ["+", 0, 2, 3, 4, 0, 66, 28, 69, 0, 73], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
0
373
#include <stdio.h> static const int MAX_CARD_SIZE = 52; static const int SENTINEL = 1000; int main(void) { int i, j, k, t, n, r, c; int p_a, p_b, p_c, deck_A[MAX_CARD_SIZE / 2], deck_B[MAX_CARD_SIZE / 2], deck_C[MAX_CARD_SIZE]; while (EOF != scanf(" %d %d", &n, &r)) { for (i = 0; i < n; i++) { deck_C[i] = i; } for (i = 0; i < r; i++) { scanf(" %d", &c); t = n / 2; for (j = 0; j < t; j++) { deck_B[j] = deck_C[j]; } deck_B[j] = SENTINEL; for (j = t; j < n; j++) { deck_A[j - t] = deck_C[j]; } deck_A[j - t] = SENTINEL; /* * for (j = 0; deck_A[j] != SENTINEL; j++) { * printf("%d ", deck_A[j]); * } * printf("\n"); * for (j = 0; deck_B[j] != SENTINEL; j++) { * printf("%d ", deck_B[j]); * } * printf("\n"); */ // merge p_a = p_b = p_c = 0; while (deck_A[p_a] != SENTINEL || deck_B[p_b] != SENTINEL) { for (k = 0; k < c; k++) { if (deck_A[p_a] == SENTINEL) { break; } deck_C[p_c++] = deck_A[p_a++]; } for (k = 0; k < c; k++) { if (deck_B[p_b] == SENTINEL) { break; } deck_C[p_c++] = deck_B[p_b++]; } } /* * for (j = 0; j < n; j++) { * printf("%d ", deck_C[j]); * } * printf("\n"); */ } printf("%d\n", deck_C[n]); } return 0; }
#include <stdio.h> static const int MAX_CARD_SIZE = 52; static const int SENTINEL = 1000; int main(void) { int i, j, k, t, n, r, c; int p_a, p_b, p_c, deck_A[MAX_CARD_SIZE / 2], deck_B[MAX_CARD_SIZE / 2], deck_C[MAX_CARD_SIZE]; while (EOF != scanf(" %d %d", &n, &r)) { for (i = 0; i < n; i++) { deck_C[i] = i; } for (i = 0; i < r; i++) { scanf(" %d", &c); t = n / 2; for (j = 0; j < t; j++) { deck_B[j] = deck_C[j]; } deck_B[j] = SENTINEL; for (j = t; j < n; j++) { deck_A[j - t] = deck_C[j]; } deck_A[j - t] = SENTINEL; /* * for (j = 0; deck_A[j] != SENTINEL; j++) { * printf("%d ", deck_A[j]); * } * printf("\n"); * for (j = 0; deck_B[j] != SENTINEL; j++) { * printf("%d ", deck_B[j]); * } * printf("\n"); */ // merge p_a = p_b = p_c = 0; while (deck_A[p_a] != SENTINEL || deck_B[p_b] != SENTINEL) { for (k = 0; k < c; k++) { if (deck_A[p_a] == SENTINEL) { break; } deck_C[p_c++] = deck_A[p_a++]; } for (k = 0; k < c; k++) { if (deck_B[p_b] == SENTINEL) { break; } deck_C[p_c++] = deck_B[p_b++]; } } /* * for (j = 0; j < n; j++) { * printf("%d ", deck_C[j]); * } * printf("\n"); */ } printf("%d\n", deck_C[n - 1]); } return 0; }
[["+", 0, 2, 3, 4, 0, 69, 71, 16, 17, 33], ["+", 0, 2, 3, 4, 0, 69, 71, 16, 12, 13]]
0
329
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) int main() { int N, R; while (cin >> N >> R) { queue<int> A, B, C; rep(i, N) { C.push(i); } rep(_, R) { int c; cin >> c; rep(i, N) { if (N / 2 <= i) { A.push(C.front()); } else { B.push(C.front()); } C.pop(); } for (; (!A.empty()) && (!B.empty());) { rep(i, c) { if (A.empty()) break; C.push(A.front()); A.pop(); } rep(i, c) { if (B.empty()) break; C.push(B.front()); B.pop(); } } } cout << C.back() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) int main() { int N, R; while (cin >> N >> R) { queue<int> A, B, C; rep(i, N) { C.push(i); } rep(_, R) { int c; cin >> c; rep(i, N) { if (N / 2 <= i) { A.push(C.front()); } else { B.push(C.front()); } C.pop(); } for (; (!A.empty()) || (!B.empty());) { rep(i, c) { if (A.empty()) break; C.push(A.front()); A.pop(); } rep(i, c) { if (B.empty()) break; C.push(B.front()); B.pop(); } } } cout << C.back() << endl; } return 0; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 98], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 106]]
1
241
while gets n = $_.to_i a = gets.split.map(&:to_i).sort s = 0 for i in 0...n s += a[i] * n-i end p s end
while gets n = $_.to_i a = gets.split.map(&:to_i).sort s = 0 for i in 0...n s += a[i] * (n-i) end p s end
[["+", 8, 170, 0, 755, 12, 738, 12, 739, 0, 24], ["+", 8, 170, 0, 755, 12, 738, 12, 739, 0, 25]]
4
43
import java.util.*; class Main { public static void main(String[] z) { Scanner s = new Scanner(System.in); for (int n, k, i; (n = s.nextInt()) > 0;) { int[] a = new int[k = s.nextInt()]; for (i = 0; i < k; ++i) a[i] = s.nextInt(); for (; n-- > 0;) for (i = 0; i < k; ++i) a[i] -= s.nextInt(); Arrays.sort(a); System.out.println(a[0] < 0 ? "NO" : "YES"); } } }
import java.util.*; class Main { public static void main(String[] z) { Scanner s = new Scanner(System.in); for (int n, k, i; (n = s.nextInt()) > 0;) { int[] a = new int[k = s.nextInt()]; for (i = 0; i < k; ++i) a[i] = s.nextInt(); for (; n-- > 0;) for (i = 0; i < k; ++i) a[i] -= s.nextInt(); Arrays.sort(a); System.out.println(a[0] < 0 ? "No" : "Yes"); } } }
[["-", 0, 492, 3, 4, 0, 510, 64, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 510, 64, 5, 0, 491], ["-", 0, 492, 3, 4, 0, 510, 75, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 510, 75, 5, 0, 491]]
3
161
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); while (true) { int n = stdIn.nextInt(); int k = stdIn.nextInt(); if (n == 0 && k == 0) { return; } int[] have = new int[k]; for (int i = 0; i < k; i++) { have[i] = stdIn.nextInt(); } boolean f = true; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { have[j] -= stdIn.nextInt(); if (have[j] < 0) { f = false; } } } if (f) { System.out.println("YES"); } else { System.out.println("NO"); } } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); while (true) { int n = stdIn.nextInt(); int k = stdIn.nextInt(); if (n == 0 && k == 0) { return; } int[] have = new int[k]; for (int i = 0; i < k; i++) { have[i] = stdIn.nextInt(); } boolean f = true; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { have[j] -= stdIn.nextInt(); if (have[j] < 0) { f = false; } } } if (f) { System.out.println("Yes"); } else { System.out.println("No"); } } } }
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
3
205
import java.util.*; class Main { static void solve(int n, int k, int[] needs, int[][] wants) { for (int i = 0; i < k; i++) { int sum = 0; for (int j = 0; j < n; j++) { sum += wants[j][i]; } if (sum > needs[i]) { System.out.println("NO"); return; } } System.out.println("YES"); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); int k = sc.nextInt(); if (n == 0 && k == 0) break; int[] needs = new int[k]; for (int i = 0; i < k; i++) needs[i] = sc.nextInt(); int[][] wants = new int[n][k]; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) wants[i][j] = sc.nextInt(); } solve(n, k, needs, wants); } } }
import java.util.*; class Main { static void solve(int n, int k, int[] needs, int[][] wants) { for (int i = 0; i < k; i++) { int sum = 0; for (int j = 0; j < n; j++) { sum += wants[j][i]; } if (sum > needs[i]) { System.out.println("No"); return; } } System.out.println("Yes"); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); int k = sc.nextInt(); if (n == 0 && k == 0) break; int[] needs = new int[k]; for (int i = 0; i < k; i++) needs[i] = sc.nextInt(); int[][] wants = new int[n][k]; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) wants[i][j] = sc.nextInt(); } solve(n, k, needs, wants); } } }
[["-", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491], ["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 491]]
3
283
import java.util.Scanner; public class Main { Scanner sc; void run() { sc = new Scanner(System.in); while (true) { boolean possible = true; int n = sc.nextInt(); int k = sc.nextInt(); if (n == 0 && k == 0) { return; } int[] s = new int[k]; int[] rs = new int[k]; for (int i = 0; i < k; i++) { s[i] = sc.nextInt(); rs[i] = 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { rs[j] += (sc.nextInt()); if (rs[j] > s[j]) { possible = false; } } } System.out.println(possible ? "YES" : "NO"); } } public static void main(String[] args) { new Main().run(); } }
import java.util.Scanner; public class Main { Scanner sc; void run() { sc = new Scanner(System.in); while (true) { boolean possible = true; int n = sc.nextInt(); int k = sc.nextInt(); if (n == 0 && k == 0) { return; } int[] s = new int[k]; int[] rs = new int[k]; for (int i = 0; i < k; i++) { s[i] = sc.nextInt(); rs[i] = 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { rs[j] += (sc.nextInt()); if (rs[j] > s[j]) { possible = false; } } } System.out.println(possible ? "Yes" : "No"); } } public static void main(String[] args) { new Main().run(); } }
[["-", 0, 492, 3, 4, 0, 510, 64, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 510, 64, 5, 0, 491], ["-", 0, 492, 3, 4, 0, 510, 75, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 510, 75, 5, 0, 491]]
3
231
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { final int N = sc.nextInt(); final int K = sc.nextInt(); if (N == 0 && K == 0) { break; } int[] drinks = new int[K]; for (int i = 0; i < K; i++) { drinks[i] = sc.nextInt(); } boolean flag = true; for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { drinks[j] -= sc.nextInt(); if (drinks[j] < 0) { flag = false; } } } System.out.println(flag ? "YES" : "NO"); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { final int N = sc.nextInt(); final int K = sc.nextInt(); if (N == 0 && K == 0) { break; } int[] drinks = new int[K]; for (int i = 0; i < K; i++) { drinks[i] = sc.nextInt(); } boolean flag = true; for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { drinks[j] -= sc.nextInt(); if (drinks[j] < 0) { flag = false; } } } System.out.println(flag ? "Yes" : "No"); } } }
[["-", 0, 492, 3, 4, 0, 510, 64, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 510, 64, 5, 0, 491], ["-", 0, 492, 3, 4, 0, 510, 75, 5, 0, 491], ["+", 0, 492, 3, 4, 0, 510, 75, 5, 0, 491]]
3
193
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); int k = sc.nextInt(); if (n == 0 && k == 0) break; int blood[] = new int[k]; for (int i = 0; i < k; i++) blood[i] = sc.nextInt(); int vamp_b[][] = new int[n][k]; int max_b[] = new int[k]; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { vamp_b[i][j] = sc.nextInt(); max_b[j] += vamp_b[i][j]; } } String ans = "YES"; for (int i = 0; i < k; i++) { if (max_b[i] > blood[i]) ans = "NO"; // System.out.println(max_b[i]+" //"+blood[i]); } System.out.println(ans); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); int k = sc.nextInt(); if (n == 0 && k == 0) break; int blood[] = new int[k]; for (int i = 0; i < k; i++) blood[i] = sc.nextInt(); int vamp_b[][] = new int[n][k]; int max_b[] = new int[k]; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { vamp_b[i][j] = sc.nextInt(); max_b[j] += vamp_b[i][j]; } } String ans = "Yes"; for (int i = 0; i < k; i++) { if (max_b[i] > blood[i]) ans = "No"; // System.out.println(max_b[i]+" //"+blood[i]); } System.out.println(ans); } } }
[["-", 8, 196, 0, 503, 49, 200, 51, 5, 0, 491], ["+", 8, 196, 0, 503, 49, 200, 51, 5, 0, 491], ["-", 0, 57, 64, 1, 0, 11, 12, 5, 0, 491], ["+", 0, 57, 64, 1, 0, 11, 12, 5, 0, 491]]
3
245
#include <stdio.h> short rml[100]; int d, g, n, k, i, j, s[100]; int main(void) { while (scanf("%d%d", &n, &k), (n == k && k == 0)) { for (i = 0; i < k; i++) scanf("%d", s + i); for (i = 0; i < n * k; i++) { scanf("%d", &g); s[i % k] -= g; if (s[i % k] < 0) rml[d] = 1; } d++; } for (i = 0; i < d; i++) printf("%s\n", (!rml[i] ? "Yes" : "No")); return 0; }
#include <stdio.h> short rml[100]; int d, g, n, k, i, j, s[100]; int main(void) { while (scanf("%d%d", &n, &k), (n != k || k)) { for (i = 0; i < k; i++) scanf("%d", s + i); for (i = 0; i < n * k; i++) { scanf("%d", &g); s[i % k] -= g; if (s[i % k] < 0) rml[d] = 1; } d++; } for (i = 0; i < d; i++) printf("%s\n", (!rml[i] ? "Yes" : "No")); return 0; }
[["-", 0, 34, 12, 23, 0, 16, 31, 16, 17, 60], ["+", 0, 34, 12, 23, 0, 16, 31, 16, 17, 79], ["-", 15, 23, 0, 34, 12, 23, 0, 16, 17, 98], ["+", 15, 23, 0, 34, 12, 23, 0, 16, 17, 106], ["-", 0, 34, 12, 23, 0, 16, 12, 16, 17, 60], ["-", 0, 34, 12, 23, 0, 16, 12, 16, 12, 13]]
0
181
#include <stdio.h> #define MAX 101 int main(void) { int N, K, i, j, sum = 0, check; int S[MAX], B[MAX][MAX]; while (scanf("%d %d", &N, &K)) { if (N == 0 && K == 0) break; else { for (i = 0; i < K; i++) { scanf("%d ", &S[i]); } for (i = 0; i < N; i++) { for (j = 0; j < K; j++) { scanf("%d ", &B[i][j]); } } check = 0; for (i = 0; i < K; i++) { for (j = 0; j < N; j++) { sum = sum + B[j][i]; } if (sum > S[i]) { check = 1; break; } sum = 0; } if (check == 0) printf("Yes\n"); else printf("No\n"); } } return 0; }
#include <stdio.h> #define MAX 101 int main(void) { int N, K, i, j, sum, check; int S[MAX], B[MAX][MAX]; while (scanf("%d %d", &N, &K)) { if (N == 0 && K == 0) break; else { for (i = 0; i < K; i++) { scanf("%d ", &S[i]); } for (i = 0; i < N; i++) { for (j = 0; j < K; j++) { scanf("%d ", &B[i][j]); } } sum = 0; check = 0; for (i = 0; i < K; i++) { for (j = 0; j < N; j++) { sum = sum + B[j][i]; } if (sum > S[i]) { check = 1; break; } sum = 0; } if (check == 0) printf("Yes\n"); else printf("No\n"); } } return 0; }
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 75, 76, 0, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35]]
0
240
#include <stdio.h> int main() { int n, k, s[105], b[105], i, j, x; while (1) { scanf("%d%d", &n, &k); if (n == 0 && k == 0) break; for (i = 0; i < k; i++) scanf("%d", &s[i]), b[i] = 0; for (i = 0; i < n; i++) { for (j = 0; j < k; j++) { scanf("%d", &x); b[j] += x; } } x = 0; for (i = 0; i < n; i++) if (b[i] > s[i]) { x = 1; break; } if (x == 1) printf("No\n"); else printf("Yes\n"); } return 0; }
#include <stdio.h> int main() { int n, k, s[105], b[105], i, j, x; while (1) { scanf("%d%d", &n, &k); if (n == 0 && k == 0) break; for (i = 0; i < k; i++) scanf("%d", &s[i]), b[i] = 0; for (i = 0; i < n; i++) { for (j = 0; j < k; j++) { scanf("%d", &x); b[j] += x; } } x = 0; for (i = 0; i < k; i++) if (b[i] > s[i]) { x = 1; break; } if (x == 1) printf("No\n"); else printf("Yes\n"); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
0
203
#include <stdio.h> int main() { int a[100]; int n, k, i, j; for (;;) { scanf("%d%d", &n, &k); if (n == 0 && k == 0) break; for (i = 0; i < k; i++) { scanf("%d", &a[i]); } while (n--) { for (i = 0; i < k; i++) { scanf("%d", &j); a[i] -= j; } } for (i = 0; i < k; i++) { if (a[i] < 0) break; } if (i == k) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <stdio.h> int main() { int a[100]; int n, k, i, j; for (;;) { scanf("%d%d", &n, &k); if (n == 0 && k == 0) break; for (i = 0; i < k; i++) { scanf("%d", &a[i]); } while (n--) { for (i = 0; i < k; i++) { scanf("%d", &j); a[i] -= j; } } for (i = 0; i < k; i++) { if (a[i] < 0) break; } if (i == k) printf("Yes\n"); else printf("No\n"); } return 0; }
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
174
k, i, j, b[999]; main(n) { for (; scanf("%d%d", &n, &k), n; puts(b[i] < 0 ? "No" : "Yes")) { for (i = 0; i < k;) scanf("%d", &b[i++]); for (; n--;) for (j = 0; j < k; b[j++] -= i) scanf("%d", &i); for (i = 0; i < k - 1;) if (b[i++] < 0) break; } exit(0); }
k, i, j, b[999]; main(n) { for (; scanf("%d%d", &n, &k), n; puts(b[i] < 0 ? "No" : "Yes")) { for (i = 0; i < k;) scanf("%d", &b[i++]); for (; n--;) for (j = 0; j < k; b[j++] -= i) scanf("%d", &i); for (i = 0; i < k - 1; i++) if (b[i] < 0) break; } exit(0); }
[["+", 0, 7, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 7, 26, 27, 17, 29], ["-", 15, 23, 0, 16, 31, 69, 71, 27, 17, 29]]
0
145
#include <stdio.h> #include <stdlib.h> int main() { int i, j, b, n, k, *blood, canMake; while (1) { scanf("%d %d", &n, &k); if (!n && !k) break; canMake = 1; blood = malloc(sizeof(int) * k); scanf("%d", blood); for (i = 1; i < k; i++) scanf(" %d", blood + i); for (i = 0; i < n; i++) { scanf("%d", &b); blood[0] -= b; if (blood[i] < 0) canMake = 0; for (j = 1; j < k; j++) { scanf(" %d", &b); blood[j] -= b; if (blood[j] < 0) canMake = 0; } } printf("%s\n", canMake ? "Yes" : "No"); } return 0; }
#include <stdio.h> #include <stdlib.h> int main() { int i, j, b, n, k, *blood, canMake; while (1) { scanf("%d %d", &n, &k); if (!n && !k) break; canMake = 1; blood = malloc(sizeof(int) * k); scanf("%d", blood); for (i = 1; i < k; i++) scanf(" %d", blood + i); for (i = 0; i < n; i++) { scanf("%d", &b); blood[0] -= b; if (blood[0] < 0) canMake = 0; for (j = 1; j < k; j++) { scanf(" %d", &b); blood[j] -= b; if (blood[j] < 0) canMake = 0; } } printf("%s\n", canMake ? "Yes" : "No"); } return 0; }
[["-", 0, 57, 15, 23, 0, 16, 31, 69, 71, 22], ["+", 0, 57, 15, 23, 0, 16, 31, 69, 71, 13]]
0
215
#include <stdio.h> #define N 100 int main() { int i; for (;;) { int s[N]; int n, k; scanf("%d%d", &n, &k); if (!(n | k)) break; for (i = 0; i < k; ++i) { scanf("%d", &s[i]); } while (n--) { for (i = 0; i < k; ++i) { int b; scanf("%d", &b); s[i] -= b; } } for (i = 0; i < k; ++i) { if (s[i] > 0) break; } puts(i == k ? "No" : "Yes"); } return (0); }
#include <stdio.h> #define N 100 int main() { int i; for (;;) { int s[N]; int n, k; scanf("%d%d", &n, &k); if (!(n | k)) break; for (i = 0; i < k; ++i) { scanf("%d", &s[i]); } while (n--) { for (i = 0; i < k; ++i) { int b; scanf("%d", &b); s[i] -= b; } } for (i = 0; i < k; ++i) { if (s[i] < 0) break; } puts(i == k ? "Yes" : "No"); } return (0); }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["-", 0, 2, 3, 4, 0, 41, 64, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 41, 64, 5, 0, 6], ["-", 0, 2, 3, 4, 0, 41, 75, 5, 0, 6], ["+", 0, 2, 3, 4, 0, 41, 75, 5, 0, 6]]
0
172
#include <stdio.h> int main() { while (1) { int N, K; int flg = 0, i, j, S[100], B; scanf("%d %d", &N, &K); if (N == 0 && K == 0) break; for (i = 0; i < K; i++) scanf("%d", &S[i]); for (i = 0; i < N; i++) { for (j = 0; j < K; j++) { scanf("%d", &B); S[j] -= B; if (S[j] < 0) flg = 1; } } switch (flg) { case 0: printf("YES\n"); break; case 1: printf("NO\n"); break; } } return 0; }
#include <stdio.h> int main() { while (1) { int N, K; int flg = 0, i, j, S[100], B; scanf("%d %d", &N, &K); if (N == 0 && K == 0) break; for (i = 0; i < K; i++) scanf("%d", &S[i]); for (i = 0; i < N; i++) { for (j = 0; j < K; j++) { scanf("%d", &B); S[j] -= B; if (S[j] < 0) flg = 1; } } switch (flg) { case 0: printf("Yes\n"); break; case 1: printf("No\n"); break; } } return 0; }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
0
181
#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() { int n, k; while (cin >> n >> k, n | k) { int t[110]; bool possible = true; rep(i, 110) t[i] = 0; rep(i, k) cin >> t[i]; rep(i, n) { rep(j, k) { int input; cin >> input; t[i]--; } } rep(i, k) if (t[i] < 0) possible = false; if (possible) cout << "Yes" << endl; else cout << "No" << 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() { int n, k; while (cin >> n >> k, n | k) { int t[110]; bool possible = true; rep(i, 110) t[i] = 0; rep(i, k) cin >> t[i]; rep(i, n) { rep(j, k) { int input; cin >> input; t[j] -= input; } } rep(i, k) if (t[i] < 0) possible = false; if (possible) cout << "Yes" << endl; else cout << "No" << endl; } }
[["-", 0, 1, 0, 27, 28, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 27, 17, 68], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 110], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 22]]
1
157
#include <iostream> using namespace std; int main() { int N, K; while (cin >> N >> K && (N | K)) { int S[100]; for (int i = 0; i < K; i++) { cin >> S[i]; } int B[100][100]; for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { cin >> B[i][j]; } } for (int i = 0; i < K; i++) { int sum = 0; for (int j = 0; j < N; j++) { sum += B[i][j]; } if (S[i] < sum) { cout << "No" << endl; goto EXIT; } } cout << "Yes" << endl; EXIT:; } return 0; }
#include <iostream> using namespace std; int main() { int N, K; while (cin >> N >> K && (N | K)) { int S[100]; for (int i = 0; i < K; i++) { cin >> S[i]; } int B[100][100]; for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { cin >> B[i][j]; } } for (int i = 0; i < K; i++) { int sum = 0; for (int j = 0; j < N; j++) { sum += B[j][i]; } if (S[i] < sum) { cout << "No" << endl; goto EXIT; } } cout << "Yes" << endl; EXIT:; } return 0; }
[["-", 0, 11, 12, 69, 28, 69, 341, 342, 0, 22], ["+", 0, 11, 12, 69, 28, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
1
196
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, K; while (cin >> N >> K && (N || K)) { vector<int> S(K); for (int i = 0; i < K; ++i) cin >> S[i]; int t; bool ok = true; for (int i = 0; i < N; ++i) { for (int j = 0; j < K; ++j) { cin >> t; S[j] -= t; if (S[i] < 0) { ok = false; } } } cout << (ok ? "Yes" : "No") << endl; } return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int N, K; while (cin >> N >> K && (N || K)) { vector<int> S(K); for (int i = 0; i < K; ++i) cin >> S[i]; int t; bool ok = true; for (int i = 0; i < N; ++i) { for (int j = 0; j < K; ++j) { cin >> t; S[j] -= t; if (S[j] < 0) { ok = false; } } } cout << (ok ? "Yes" : "No") << endl; } return 0; }
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22]]
1
152
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define pb(n) push_back(n) #define mp(n, m) make_pair(n, m) #define fi first #define se second #define all(r) (r).begin(), (r).end() #define REP(i, s, e) for (int i = (s); i < (e); i++) #define rep(i, n) REP(i, 0, n) #define REPE(i, s, e) for (int i = s; i > e; i--) #define repe(i, n) REPE(i, n, -1) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<vi> vvi; const int IMAX = ((1 << 30) - 1) * 2 + 1; const int INF = 100000000; const double EPS = 1e-10; // int mod=1000000007 const int MAX_V = 10000; int main() { int n, m; while (cin >> n >> m) { if (n == 0 && m == 0) break; vi s(n, 0); rep(i, m) cin >> s[i]; int t; rep(i, n) { rep(j, m) { cin >> t; s[j] -= t; } } sort(all(s)); cout << (s[0] < 0 ? "No" : "Yes") << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define pb(n) push_back(n) #define mp(n, m) make_pair(n, m) #define fi first #define se second #define all(r) (r).begin(), (r).end() #define REP(i, s, e) for (int i = (s); i < (e); i++) #define rep(i, n) REP(i, 0, n) #define REPE(i, s, e) for (int i = s; i > e; i--) #define repe(i, n) REPE(i, n, -1) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<vi> vvi; const int IMAX = ((1 << 30) - 1) * 2 + 1; const int INF = 100000000; const double EPS = 1e-10; // int mod=1000000007 const int MAX_V = 10000; int main() { int n, m; while (cin >> n >> m) { if (n == 0 && m == 0) break; vi s(m, 0); rep(i, m) cin >> s[i]; int t; rep(i, n) { rep(j, m) { cin >> t; s[j] -= t; } } sort(all(s)); cout << (s[0] < 0 ? "No" : "Yes") << endl; } }
[["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 22]]
1
291
#include <iostream> using namespace std; int n, m, x, s[100]; int main() { while (cin >> n >> m, n + m) { for (int i = 0; i < m; i++) cin >> s[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> x, s[x]--; } int f = 1; for (int i = 0; i < m; i++) { if (s[i] < 0) f = 0; } cout << (f ? "Yes" : "No") << endl; } }
#include <iostream> using namespace std; int n, m, x, s[100]; int main() { while (cin >> n >> m, n + m) { for (int i = 0; i < m; i++) cin >> s[i]; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> x, s[j] -= x; } int f = 1; for (int i = 0; i < m; i++) { if (s[i] < 0) f = 0; } cout << (f ? "Yes" : "No") << endl; } }
[["-", 0, 34, 12, 27, 28, 69, 341, 342, 0, 22], ["+", 0, 34, 12, 11, 31, 69, 341, 342, 0, 22], ["-", 0, 7, 8, 1, 0, 34, 12, 27, 17, 68], ["+", 0, 7, 8, 1, 0, 34, 12, 11, 17, 110], ["+", 0, 7, 8, 1, 0, 34, 12, 11, 12, 22]]
1
149
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define vi vector<int> #define vvi vector<vector<int>> #define ll long long int #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> #define ld long double #define INF 1e9 #define EPS 0.0000000001 #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define all(in) in.begin(), in.end() #define MAX 9999999 using namespace std; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; int main() { int n, k; while (cin >> n >> k, n + k) { bool flag = true; vi v(k, 0); rep(i, k) cin >> v[i]; rep(i, n) { rep(j, k) { int temp; cin >> temp; v[j] -= temp; if (v[j] < 0) flag = false; } } if (flag) cout << "Yes" << endl; else cout << "N0" << endl; } }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define vi vector<int> #define vvi vector<vector<int>> #define ll long long int #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vc vector<char> #define vs vector<string> #define ld long double #define INF 1e9 #define EPS 0.0000000001 #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define all(in) in.begin(), in.end() #define MAX 9999999 using namespace std; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; int main() { int n, k; while (cin >> n >> k, n + k) { bool flag = true; vi v(k, 0); rep(i, k) cin >> v[i]; rep(i, n) { rep(j, k) { int temp; cin >> temp; v[j] -= temp; if (v[j] < 0) flag = false; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
231
#include <iostream> using namespace std; int main() { long long int N, K, S[100] = {}, a, flag = 0; while (1) { cin >> N >> K; if (N == 0 && K == 0) break; for (int i = 0; i < K; i++) { cin >> S[i]; } for (int j = 0; j < N; j++) { for (int i = 0; i < K; i++) { cin >> a; S[i] -= a; } } for (int i = 0; i < N; i++) { if (S[i] < 0) { flag++; break; } } if (!flag) { cout << "Yes\n"; } else { cout << "No\n"; } } return 0; }
#include <iostream> using namespace std; int main() { long long int N, K, S[101] = {}, a, flag = 0; while (1) { cin >> N >> K; if (N == 0 && K == 0) break; for (int i = 0; i < K; i++) { cin >> S[i]; } for (int j = 0; j < N; j++) { for (int i = 0; i < K; i++) { cin >> a; S[i] -= a; } } flag = 0; for (int i = 0; i < K; i++) { if (S[i] < 0) { flag++; break; } } if (!flag) { cout << "Yes\n"; } else { cout << "No\n"; } } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22]]
1
182
#include <iostream> using namespace std; int main() { int n, k, l; while (1) { cin >> n >> k; if (n == 0 && k == 0) break; int s[k]; int b[k]; for (int i = 0; i < k; i++) { s[i] = 0; b[i] = 0; cin >> s[i]; } for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) cin >> l, b[j] += l; int f = 0; for (int i = 0; i < k; i++) if (s[i] < b[i]) f = 1; if (f == 0) cout << "YES\n"; else cout << "NO\n"; } }
#include <iostream> using namespace std; int main() { int n, k, l; while (1) { cin >> n >> k; if (n == 0 && k == 0) break; int s[k]; int b[k]; for (int i = 0; i < k; i++) { s[i] = 0; b[i] = 0; cin >> s[i]; } for (int i = 0; i < n; i++) for (int j = 0; j < k; j++) cin >> l, b[j] += l; int f = 0; for (int i = 0; i < k; i++) if (s[i] < b[i]) f = 1; if (f == 0) cout << "Yes\n"; else cout << "No\n"; } }
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["-", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6]]
1
187
#include <iostream> #include <vector> using namespace std; int main() { int n, k, t; while (cin >> n >> k && n || k) { bool flag = true; vector<int> blood(k); for (int i = 0; i < k; i++) { cin >> blood[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { cin >> t; blood[j] -= t; if (blood[j] < 0) flag = false; } } if (flag) cout << "YES"; else cout << "NO"; cout << endl; } }
#include <iostream> #include <vector> using namespace std; int main() { int n, k, t; while (cin >> n >> k && n || k) { bool flag = true; vector<int> blood(k); for (int i = 0; i < k; i++) { cin >> blood[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { cin >> t; blood[j] -= t; if (blood[j] < 0) flag = false; } } if (flag) cout << "Yes"; else cout << "No"; cout << endl; } }
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["-", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6]]
1
149
#include <stdio.h> int main() { int fami, kind, need[100], chi[100]; int i, j, judge = 0, temp; for (;; judge = 0) { for (i = 0; i < 100; i++) { need[i] = 0; chi[i] = 0; } scanf("%d%d", &fami, &kind); if (fami == 0 && kind == 0) break; for (i = 0; i < kind; i++) scanf("%d", &chi[i]); for (i = 0; i < fami; i++) { for (j = 0; j < kind; j++) { scanf("%d", &temp); need[j] += temp; } } for (i = 0; i < kind; i++) { if (chi[i] - need[i] < 0) { judge = 1; break; } } if (judge == 0) puts("YES"); else puts("NO"); } return 0; }
#include <stdio.h> int main() { int fami, kind, need[100], chi[100]; int i, j, judge = 0, temp; for (;; judge = 0) { for (i = 0; i < 100; i++) { need[i] = 0; chi[i] = 0; } scanf("%d%d", &fami, &kind); if (fami == 0 && kind == 0) break; for (i = 0; i < kind; i++) scanf("%d", &chi[i]); for (i = 0; i < fami; i++) { for (j = 0; j < kind; j++) { scanf("%d", &temp); need[j] += temp; } } for (i = 0; i < kind; i++) { if (chi[i] - need[i] < 0) { judge = 1; break; } } if (judge == 0) puts("Yes"); else puts("No"); } return 0; }
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
232
#include <iostream> using namespace std; int main() { int n, k, i, j; int b[1012]; for (;;) { cin >> n >> k; if (n == 0 && k == 0) break; for (i = 0; i < k; i++) cin >> b[i]; int a, flag = 1; for (i = 0; i < n; i++) { for (j = 0; j < k; j++) { cin >> a; b[j] -= a; if (b[i] < 0) flag = 0; } } if (flag == 1) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <iostream> using namespace std; int main() { int n, k, i, j; int b[1012]; for (;;) { cin >> n >> k; if (n == 0 && k == 0) break; for (i = 0; i < k; i++) cin >> b[i]; int a, flag = 1; for (i = 0; i < n; i++) { for (j = 0; j < k; j++) { cin >> a; b[j] -= a; if (b[j] < 0) flag = 0; } } if (flag == 1) cout << "Yes" << endl; else cout << "No" << endl; } }
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22]]
1
156
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { while (true) { int N, K; cin >> N >> K; if (N == 0 && K == 0) break; vector<int> S(K); for (int i = 0; i < K; i++) cin >> S[i]; for (int i = 0; i < N; i++) for (int j = 0; j < K; j++) { int t; cin >> t; S[j] -= t; } if (*min_element(S.begin(), S.end()) >= 0) cout << "YES" << endl; else cout << "NO" << endl; } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { while (true) { int N, K; cin >> N >> K; if (N == 0 && K == 0) break; vector<int> S(K); for (int i = 0; i < K; i++) cin >> S[i]; for (int i = 0; i < N; i++) for (int j = 0; j < K; j++) { int t; cin >> t; S[j] -= t; } if (*min_element(S.begin(), S.end()) >= 0) cout << "Yes" << endl; else cout << "No" << endl; } }
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
156
#include <fstream> #include <iostream> #include <vector> using namespace std; int N; int K; int *S; int **B; bool calc() { int sumB = 0; for (int j = 0; j < K; j++) { sumB = 0; for (int i = 0; i < N; i++) { sumB += B[i][j]; } if (S[j] < sumB) { return false; } } return true; } void solve() { ifstream ifs("prob1019.txt"); while (1) { ifs >> N; ifs >> K; if (N == 0 && K == 0) break; S = new int[K]; B = new int *[N]; for (int i = 0; i < K; i++) { ifs >> S[i]; } for (int i = 0; i < N; i++) { B[i] = new int[K]; for (int j = 0; j < K; j++) { ifs >> B[i][j]; } } // for(int i = 0; i < N; i++){ // for(int j = 0; j < K; j++){ // cout << B[i][j] << " " << flush; // } // cout << endl; //} if (calc()) { cout << "Yes" << endl; } else cout << "No" << endl; delete[] S; for (int i = 0; i < N; i++) { delete[] B[i]; } delete[] B; } } int main() { solve(); int x; cin >> x; return 0; }
#include <fstream> #include <iostream> #include <vector> using namespace std; int N; int K; int *S; int **B; bool calc() { int sumB = 0; for (int j = 0; j < K; j++) { sumB = 0; for (int i = 0; i < N; i++) { sumB += B[i][j]; } if (S[j] < sumB) { return false; } } return true; } void solve() { ifstream ifs("prob1019.txt"); while (1) { // ifs >> N; // ifs >> K; cin >> N; cin >> K; if (N == 0 && K == 0) break; S = new int[K]; B = new int *[N]; for (int i = 0; i < K; i++) { cin >> S[i]; // ifs >> S[i]; } for (int i = 0; i < N; i++) { B[i] = new int[K]; for (int j = 0; j < K; j++) { cin >> B[i][j]; // ifs >> B[i][j]; } } if (calc()) { cout << "Yes" << endl; } else cout << "No" << endl; delete[] S; for (int i = 0; i < N; i++) { delete[] B[i]; } delete[] B; } } int main() { solve(); int x; cin >> x; return 0; }
[["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 31, 22]]
1
317
#include <stdio.h> int main() { int n, k, s[100], t; while (true) { scanf("%d%d", &n, &k); if (n == 0 && k == 0) break; for (int i = 0; i < k; ++i) { scanf("%d", &t); s[i] = t; } for (int i = 0; i < n; ++i) { for (int j = 0; j < k; ++j) { scanf("%d", &t); s[j] -= t; } } bool empty = false; for (int i = 0; i < n; ++i) { if (s[i] < 0) empty = true; } if (empty) printf("No\n"); else printf("Yes\n"); } return 0; }
#include <stdio.h> int main() { int n, k, s[100], t; while (true) { scanf("%d%d", &n, &k); if (n == 0 && k == 0) break; for (int i = 0; i < k; ++i) { scanf("%d", &t); s[i] = t; } for (int i = 0; i < n; ++i) { for (int j = 0; j < k; ++j) { scanf("%d", &t); s[j] -= t; } } bool empty = false; for (int i = 0; i < k; ++i) { if (s[i] < 0) { empty = true; break; } } if (empty) printf("No\n"); else printf("Yes\n"); } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
1
191
#include <algorithm> #include <iostream> #include <string.h> #include <string> #include <vector> using namespace std; int exist[100000]; int needed[100000]; int main() { int n, k; while (1) { cin >> n >> k; if (n == 0) break; memset(exist, 0, sizeof(exist)); memset(needed, 0, sizeof(needed)); for (int i = 0; i < k; i++) { cin >> exist[i]; } int tmp; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { cin >> tmp; needed[j] += tmp; } } int ok = 1; for (int i = 0; i < k; i++) { if (exist[i] < needed[i]) { ok = 0; break; } } (ok == 1) ? cout << "YES" << endl : cout << "NO" << endl; } return 0; }
#include <algorithm> #include <iostream> #include <string.h> #include <string> #include <vector> using namespace std; int exist[100000]; int needed[100000]; int main() { int n, k; while (1) { cin >> n >> k; if (n == 0) break; memset(exist, 0, sizeof(exist)); memset(needed, 0, sizeof(needed)); for (int i = 0; i < k; i++) { cin >> exist[i]; } int tmp; for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { cin >> tmp; needed[j] += tmp; } } int ok = 1; for (int i = 0; i < k; i++) { if (exist[i] < needed[i]) { ok = 0; break; } } (ok == 1) ? cout << "Yes" << endl : cout << "No" << endl; } return 0; }
[["-", 0, 41, 64, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 41, 64, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 41, 75, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 41, 75, 16, 31, 16, 12, 5, 0, 6]]
1
216
#include <iostream> #include <vector> using namespace std; int main() { int x, K, N; int pre[200], rea[200]; while (cin >> N >> K, K || N) { for (int i = 0; i < K; i++) { rea[i] = 0; cin >> x; pre[i] = x; } for (int i = 0; i < N; i++) for (int j = 0; j < K; j++) { cin >> x; rea[j] += x; } int i; for (i = 0; i < K; i++) { if (rea[i] < pre[i]) { cout << "Yes" << endl; break; } } if (i == K) cout << "No" << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int x, K, N; int pre[200], rea[200]; while (cin >> N >> K, K || N) { for (int i = 0; i < K; i++) { rea[i] = 0; cin >> x; pre[i] = x; } for (int i = 0; i < N; i++) for (int j = 0; j < K; j++) { cin >> x; rea[j] += x; } int i; for (i = 0; i < K; i++) { if (rea[i] > pre[i]) { cout << "No" << endl; break; } } if (i == K) cout << "Yes" << endl; } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
180
#include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int N, K; while (scanf("%d %d ", &N, &K) == 2) { if (N == 0 && K == 0) { break; } // printf("(N, K) = (%d, %d)\n", N, K); vector<int> S(K); for (int i = 0; i < K; i++) { int s; scanf("%d ", &s); S[i] = s; } bool flag = true; for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { int b; scanf("%d ", &b); S[j] -= b; if (S[j] < 0) { flag = false; } } } if (flag) { printf("Yen\n"); } else { printf("No\n"); } } }
#include <cstdio> #include <iostream> #include <vector> using namespace std; int main() { int N, K; while (scanf("%d %d ", &N, &K) == 2) { if (N == 0 && K == 0) { break; } // printf("(N, K) = (%d, %d)\n", N, K); vector<int> S(K); for (int i = 0; i < K; i++) { int s; scanf("%d ", &s); S[i] = s; } bool flag = true; for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { int b; scanf("%d ", &b); S[j] -= b; if (S[j] < 0) { flag = false; } } } if (flag) { printf("Yes\n"); } else { printf("No\n"); } } }
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
197
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { for (;;) { int n, k; cin >> n >> k; if (n == 0) return 0; vector<int> blood(k); for (int i = 0; i < k; ++i) cin >> blood[i]; for (int i = 0; i < n; ++i) { for (int j = 0; j < k; ++j) { int tmp; cin >> tmp; blood[j] -= tmp; } } if (*(min_element(blood.begin(), blood.end())) < 0) cout << "NO" << endl; else cout << "YES" << endl; } }
#include <algorithm> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; int main() { for (;;) { int n, k; cin >> n >> k; if (n == 0) return 0; vector<int> blood(k); for (int i = 0; i < k; ++i) cin >> blood[i]; for (int i = 0; i < n; ++i) { for (int j = 0; j < k; ++j) { int tmp; cin >> tmp; blood[j] -= tmp; } } if (*(min_element(blood.begin(), blood.end())) < 0) cout << "No" << endl; else cout << "Yes" << endl; } }
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
184
#include <iostream> #include <vector> using namespace std; int N, K, tmp; void solve() { vector<int> bloods(K), family(K); for (int i = 0; i < K; i += 1) cin >> bloods[i]; for (int i = 0; i < N; i += 1) { for (int j = 0; j < K; j += 1) { cin >> tmp; family[j] += tmp; } } // calc for (int i = 0; i < K; i += 1) { if (family[i] > bloods[i]) { cout << "NO" << endl; return; } } cout << "YES" << endl; } int main(int argc, char const *argv[]) { while (true) { cin >> N >> K; if (N == 0 && K == 0) break; solve(); } return 0; }
#include <iostream> #include <vector> using namespace std; int N, K, tmp; void solve() { vector<int> bloods(K), family(K); for (int i = 0; i < K; i += 1) cin >> bloods[i]; for (int i = 0; i < N; i += 1) { for (int j = 0; j < K; j += 1) { cin >> tmp; family[j] += tmp; } } // calc for (int i = 0; i < K; i += 1) { if (family[i] > bloods[i]) { cout << "No" << endl; return; } } cout << "Yes" << endl; } int main(int argc, char const *argv[]) { while (true) { cin >> N >> K; if (N == 0 && K == 0) break; solve(); } return 0; }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
198
#include <cstdio> int s[110], n, m; int main() { int i, j, k, l; bool pass; while (1) { scanf("%d%d", &n, &m); if (n == 0 && m == 0) break; for (i = 0; i < m; i++) scanf("%d", &s[i]); for (i = 0; i < n; i++) for (j = 0; j < m; j++) { scanf("%d", &k); s[j] -= k; } pass = true; for (i = 0; i < m; i++) if (s[i] < 0) { pass = false; break; } if (pass) printf("YES\n"); else printf("NO\n"); } return 0; }
#include <cstdio> int s[110], n, m; int main() { int i, j, k, l; bool pass; while (1) { scanf("%d%d", &n, &m); if (n == 0 && m == 0) break; for (i = 0; i < m; i++) scanf("%d", &s[i]); for (i = 0; i < n; i++) for (j = 0; j < m; j++) { scanf("%d", &k); s[j] -= k; } pass = true; for (i = 0; i < m; i++) if (s[i] < 0) { pass = false; break; } if (pass) printf("Yes\n"); else printf("No\n"); } return 0; }
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
190
#include <iostream> #include <vector> using namespace std; void solve() { int N, K; while (cin >> N >> K) { if (!N && !K) { break; } vector<int> S(K); vector<vector<int>> B(N); for (int i = 0; i < N; ++i) { B[i].resize(K); } for (int i = 0; i < K; ++i) { cin >> S[i]; } for (int i = 0; i < N; ++i) { for (int j = 0; j < K; ++j) { cin >> B[i][j]; } } bool flag = true; for (int i = 0; i < K; ++i) { int sum = 0; for (int j = 0; j < N; ++j) { sum += B[j][i]; } if (S[i] < sum) { flag = false; break; } } if (flag) { cout << "YES" << endl; } else { cout << "NO" << endl; } } } int main() { solve(); return (0); }
#include <iostream> #include <vector> using namespace std; void solve() { int N, K; while (cin >> N >> K) { if (!N && !K) { break; } vector<int> S(K); vector<vector<int>> B(N); for (int i = 0; i < N; ++i) { B[i].resize(K); } for (int i = 0; i < K; ++i) { cin >> S[i]; } for (int i = 0; i < N; ++i) { for (int j = 0; j < K; ++j) { cin >> B[i][j]; } } bool flag = true; for (int i = 0; i < K; ++i) { int sum = 0; for (int j = 0; j < N; ++j) { sum += B[j][i]; } if (S[i] < sum) { flag = false; break; } } if (flag) { cout << "Yes" << endl; } else { cout << "No" << endl; } } } int main() { solve(); return (0); }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
262
#include <iostream> using namespace std; int s[100]; int main() { int n, k; while (cin >> n >> k) { if (!n && !k) break; bool flag = true; for (int i = 0; i < k; i++) { cin >> s[k]; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { int a; cin >> a; s[j] -= a; if (s[j] > 0) flag = false; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <iostream> using namespace std; int s[100]; int main() { int n, k; while (cin >> n >> k) { if (!n && !k) break; bool flag = true; for (int i = 0; i < k; i++) { cin >> s[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { int a; cin >> a; s[j] -= a; if (s[j] < 0) flag = false; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
[["-", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 16, 12, 69, 341, 342, 0, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
154
#include <iostream> #include <vector> using namespace std; int main() { int n, k; while (cin >> n >> k, n != 0 && k != 0) { bool flug = false; vector<int> blood_stock(k); for (int i = 0; i < k; i++) { cin >> blood_stock[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { int tmp; cin >> tmp; blood_stock[j] -= tmp; } } for (int i = 0; i < k; i++) { if (blood_stock[i] < 0) { cout << "NO" << endl; flug = true; break; } } if (flug == false) { cout << "YES" << endl; } } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int n, k; while (cin >> n >> k, n != 0 && k != 0) { bool flug = false; vector<int> blood_stock(k); for (int i = 0; i < k; i++) { cin >> blood_stock[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { int tmp; cin >> tmp; blood_stock[j] -= tmp; } } for (int i = 0; i < k; i++) { if (blood_stock[i] < 0) { cout << "No" << endl; flug = true; break; } } if (flug == false) { cout << "Yes" << endl; } } return 0; }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
180
#include <iostream> #define MAX_K 110 using namespace std; int main() { int n, k; while (cin >> n >> k) { if (n == 0 && k == 0) break; int dx[MAX_K] = {0}, max[MAX_K] = {0}; for (int i = 0; i < k; i++) { cin >> max[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { int tmp; cin >> tmp; dx[j] += tmp; } } bool flag = false; for (int i = 0; i < k; i++) { if (dx[i] > max[i]) { flag = true; break; } } if (flag) cout << "NO"; else cout << "YES"; cout << endl; } return 0; }
#include <iostream> #define MAX_K 110 using namespace std; int main() { int n, k; while (cin >> n >> k) { if (n == 0 && k == 0) break; int dx[MAX_K] = {0}, max[MAX_K] = {0}; for (int i = 0; i < k; i++) { cin >> max[i]; } for (int i = 0; i < n; i++) { for (int j = 0; j < k; j++) { int tmp; cin >> tmp; dx[j] += tmp; } } bool flag = false; for (int i = 0; i < k; i++) { if (dx[i] > max[i]) { flag = true; break; } } if (flag) cout << "No"; else cout << "Yes"; cout << endl; } return 0; }
[["-", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["+", 0, 57, 64, 1, 0, 16, 12, 5, 0, 6], ["-", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6], ["+", 75, 76, 0, 1, 0, 16, 12, 5, 0, 6]]
1
195
#include <iostream> using namespace std; int main() { int n, k; int s[100]; bool f; while (cin >> n >> k && (n || k)) { for (int i = 0; i < k; i++) cin >> s[i]; f = true; for (int i = 0; i < n; i++) { for (int j = 0, l; j < k; j++) { cin >> l; s[k] -= l; if (s[k] < 0) f = false; } } if (f) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n, k; int s[100]; bool f; while (cin >> n >> k && (n || k)) { for (int i = 0; i < k; i++) cin >> s[i]; f = true; for (int i = 0; i < n; i++) { for (int j = 0, l; j < k; j++) { cin >> l; s[j] -= l; if (s[j] < 0) f = false; } } if (f) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22]]
1
149
#include <stdio.h> int main() { int N, K; int S[100]; int B; int count; int h = 1; int i, j; scanf("%d %d", &N, &K); while ((N != 0) && (K != 0)) { h = 1; for (i = 0; i < K; i++) { scanf("%d", &S[i]); } for (i = 0; i < N; i++) { for (j = 0; j < K; j++) { scanf("%d", &B); S[i] = S[i] - B; if (S[i] < 0) { h = 0; } } } if (h == 1) { printf("Yes\n"); } else { printf("No\n"); } scanf("%d %d", &N, &K); } return 0; }
#include <stdio.h> int main() { int N, K; int S[100]; int B; int count; int h = 1; int i, j; scanf("%d %d", &N, &K); while ((N != 0) && (K != 0)) { h = 1; for (i = 0; i < K; i++) { scanf("%d", &S[i]); } for (i = 0; i < N; i++) { for (j = 0; j < K; j++) { scanf("%d", &B); S[j] = S[j] - B; if (S[j] < 0) { h = 0; } } } if (h == 1) { printf("Yes\n"); } else { printf("No\n"); } scanf("%d %d", &N, &K); } return 0; }
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 0, 11, 12, 16, 31, 69, 341, 342, 0, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22]]
1
206
#include <stdio.h> bool check(int m, int k) { int blood[101]; int eats[101] = {0}; for (int i = 0; i < k; i++) scanf("%d", &blood[i]); for (int i = 0; i < m; i++) { for (int j = 0; j < k; j++) { int temp; scanf("%d", &temp); eats[j] += temp; } } for (int i = 0; i < k; i++) if (eats[i] > blood[i]) return false; return true; } int main() { int member, kind; while (true) { scanf("%d %d", &member, &kind); if (member == 0 && kind == 0) break; check(member, kind) ? printf("YES\n") : printf("NO\n"); } }
#include <stdio.h> bool check(int m, int k) { int blood[101]; int eats[101] = {0}; for (int i = 0; i < k; i++) scanf("%d", &blood[i]); for (int i = 0; i < m; i++) { for (int j = 0; j < k; j++) { int temp; scanf("%d", &temp); eats[j] += temp; } } for (int i = 0; i < k; i++) if (eats[i] > blood[i]) return false; return true; } int main() { int member, kind; while (true) { scanf("%d %d", &member, &kind); if (member == 0 && kind == 0) break; check(member, kind) ? printf("Yes\n") : printf("No\n"); } }
[["-", 0, 41, 64, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 41, 64, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 41, 75, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 41, 75, 2, 3, 4, 0, 5, 0, 6]]
1
205
#include <algorithm> #include <cstdio> #include <iostream> #include <utility> #include <vector> using namespace std; int N, K, S[100]; int main() { while (true) { scanf("%d %d", &N, &K); if (N == 0 && K == 0) break; for (int i = 0; i < K; ++i) { scanf("%d", S + i); } for (int i = 0; i < N; ++i) { for (int j = 0; j < K; ++j) { int B; scanf("%d", &B); S[j] -= B; } } cout << (*min_element(S, S + N) >= 0 ? "Yes" : "No") << endl; } return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <utility> #include <vector> using namespace std; int N, K, S[100]; int main() { while (true) { scanf("%d %d", &N, &K); if (N == 0 && K == 0) break; for (int i = 0; i < K; ++i) { scanf("%d", S + i); } for (int i = 0; i < N; ++i) { for (int j = 0; j < K; ++j) { int B; scanf("%d", &B); S[j] -= B; } } cout << (*min_element(S, S + K) >= 0 ? "Yes" : "No") << endl; } return 0; }
[["-", 31, 66, 28, 2, 3, 4, 0, 16, 12, 22], ["+", 31, 66, 28, 2, 3, 4, 0, 16, 12, 22]]
1
169
#include <iostream> #include <string> using namespace std; int main() { int N, K; while (cin >> N >> K) { if (N == 0 && K == 0) break; int S[K]; for (int i = 0; i < K; i++) { cin >> S[i]; } for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { int b; cin >> b; S[j] -= b; } } string ans = "YES"; for (int i = 0; i < K; i++) { if (S[i] < 0) { ans = "NO"; break; } } cout << ans << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main() { int N, K; while (cin >> N >> K) { if (N == 0 && K == 0) break; int S[K]; for (int i = 0; i < K; i++) { cin >> S[i]; } for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { int b; cin >> b; S[j] -= b; } } string ans = "Yes"; for (int i = 0; i < K; i++) { if (S[i] < 0) { ans = "No"; } } cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 51, 5, 0, 6], ["+", 8, 9, 0, 43, 49, 50, 51, 5, 0, 6], ["-", 64, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["+", 64, 9, 0, 1, 0, 11, 12, 5, 0, 6], ["-", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["-", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94]]
1
167
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { int N, K; int S[101]; int B; while (cin >> N >> K) { if (N == 0 && K == 0) break; bool flag = 1; for (int i = 0; i < K; i++) { cin >> S[i]; } for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { cin >> B; S[j] -= B; if (S[i] < 0) flag = 0; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <cstdio> #include <cstring> #include <iostream> using namespace std; int main() { int N, K; int S[101]; int B; while (cin >> N >> K) { if (N == 0 && K == 0) break; bool flag = 1; for (int i = 0; i < K; i++) { cin >> S[i]; } for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { cin >> B; S[j] -= B; if (S[j] < 0) flag = 0; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22]]
1
160
// 58 #include <algorithm> #include <iostream> using namespace std; int main() { for (int N, K; cin >> N >> K, N | K;) { int s[100]; for (int i = 0; i < K; i++) { cin >> s[i]; } bool fail = false; for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { int b; cin >> b; s[j] -= b; if (s[j] < 0) { fail = true; } } } cout << ((fail) ? "NO" : "YES") << endl; } return 0; }
// 58 #include <algorithm> #include <iostream> using namespace std; int main() { for (int N, K; cin >> N >> K, N | K;) { int s[100]; for (int i = 0; i < K; i++) { cin >> s[i]; } bool fail = false; for (int i = 0; i < N; i++) { for (int j = 0; j < K; j++) { int b; cin >> b; s[j] -= b; if (s[j] < 0) { fail = true; } } } cout << ((fail) ? "No" : "Yes") << endl; } return 0; }
[["-", 31, 16, 12, 23, 0, 41, 64, 5, 0, 6], ["+", 31, 16, 12, 23, 0, 41, 64, 5, 0, 6], ["-", 31, 16, 12, 23, 0, 41, 75, 5, 0, 6], ["+", 31, 16, 12, 23, 0, 41, 75, 5, 0, 6]]
1
151
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define EACH(t, i, c) for (t::iterator i = (c).begin(); i != (c).end(); ++i) const double EPS = 1e-10; const double PI = acos(-1.0); int main() { int n, k; while (cin >> n >> k, n && k) { vi s(k); vvi b(n, vi(k)); REP(i, k) { cin >> s[i]; } REP(i, n) { REP(j, k) { cin >> b[i][j]; s[j] -= b[i][j]; } } REP(i, n) { if (s[i] < 0) { cout << "No" << endl; goto end; } } cout << "Yes" << endl; end:; } }
#include <algorithm> #include <cassert> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<int, int> pii; typedef long long ll; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((s).find(e) != (s).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define EACH(t, i, c) for (t::iterator i = (c).begin(); i != (c).end(); ++i) const double EPS = 1e-10; const double PI = acos(-1.0); int main() { int n, k; while (cin >> n >> k, n || k) { vi s(k); vvi b(n, vi(k)); REP(i, k) { cin >> s[i]; } REP(i, n) { REP(j, k) { cin >> b[i][j]; s[j] -= b[i][j]; } } REP(i, k) { if (s[i] < 0) { cout << "No" << endl; goto end; } } cout << "Yes" << endl; end:; } }
[["-", 0, 52, 15, 339, 51, 34, 12, 16, 17, 98], ["+", 0, 52, 15, 339, 51, 34, 12, 16, 17, 106], ["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
334
#include <cstdio> #include <iostream> using namespace std; int main(void) { int n, k; int s[111]; while (cin >> n >> k && n) { for (int i = 0; i < k; i++) { cin >> s[i]; } for (int j = 0; j < n; j++) { for (int i = 0; i < k; i++) { int b; cin >> b; s[i] -= b; } } bool f = true; for (int i = 0; i < k; i++) { if (s[i] < 0) { f = false; cout << "No" << endl; } } if (f) cout << "Yes" << endl; } }
#include <cstdio> #include <iostream> using namespace std; int main(void) { int n, k; int s[111]; while (cin >> n >> k && n) { for (int i = 0; i < k; i++) { cin >> s[i]; } for (int j = 0; j < n; j++) { for (int i = 0; i < k; i++) { int b; cin >> b; s[i] -= b; } } bool f = true; for (int i = 0; i < k; i++) { if (s[i] < 0) { f = false; cout << "No" << endl; break; } } if (f) cout << "Yes" << endl; } }
[["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
1
163
#include <stdio.h> int s[100]; int main() { int n, k; int i, j; while (1) { scanf("%d %d", &n, &k); if (n == 0) return 0; for (i = 0; i < k; i++) scanf("%d", &s[i]); for (i = 0; i < n; i++) { for (j = 0; j < k; j++) { int x; scanf("%d", &x); s[j] -= x; } } for (i = 0; i < k; i++) if (s[i] < 0) break; if (i == k) printf("YES\n"); else printf("NO\n"); } }
#include <stdio.h> int s[100]; int main() { int n, k; int i, j; while (1) { scanf("%d %d", &n, &k); if (n == 0) return 0; for (i = 0; i < k; i++) scanf("%d", &s[i]); for (i = 0; i < n; i++) { for (j = 0; j < k; j++) { int x; scanf("%d", &x); s[j] -= x; } } for (i = 0; i < k; i++) if (s[i] < 0) break; if (i == k) printf("Yes\n"); else printf("No\n"); } }
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
175
#include <stdio.h> main() { int N, K, blood[101], family[101], tmp, i, j, x; while (1) { scanf("%d %d", &N, &K); if (N == 0 && K == 0) break; tmp = 1; for (i = 0; i < K; i++) scanf("%d", &blood[i]); for (i = 0; i < N; i++) { for (j = 0; j < K; j++) { scanf("%d", &x); blood[j] -= x; if (blood[j] < 0) tmp = 0; } } if (tmp == 0) printf("no\n"); else printf("yes\n"); } }
#include <stdio.h> main() { int N, K, blood[101], family[101], tmp, i, j, x; while (1) { scanf("%d %d", &N, &K); if (N == 0 && K == 0) break; tmp = 1; for (i = 0; i < K; i++) scanf("%d", &blood[i]); for (i = 0; i < N; i++) { for (j = 0; j < K; j++) { scanf("%d", &x); blood[j] -= x; if (blood[j] < 0) tmp = 0; } } if (tmp == 0) printf("No\n"); else printf("Yes\n"); } }
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
174
#include <iostream> #include <string> using namespace std; int main(void) { int n, k; while (cin >> n >> k, n | k) { bool ok = true; int r[100], tmp; for (int i = 0; i < k; i++) cin >> r[i]; for (int j = 0; j < n; j++) { for (int i = 0; i < k; i++) { cin >> tmp; r[i] -= tmp; if (r[i] < 0) ok = false; } } if (ok) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
#include <iostream> #include <string> using namespace std; int main(void) { int n, k; while (cin >> n >> k, n | k) { bool ok = true; int r[100], tmp; for (int i = 0; i < k; i++) cin >> r[i]; for (int j = 0; j < n; j++) { for (int i = 0; i < k; i++) { cin >> tmp; r[i] -= tmp; if (r[i] < 0) ok = false; } } if (ok) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
148
loop do n, k = gets.split.map(&:to_i) break if n == 0 s, ans = gets.split.map(&:to_i), "Yes" n.times do b = gets.split.map(&:to_i) k.times do |i| s[i] -= b[i] ans = "No" if s[i] < 0 end end p ans end
loop do n, k = gets.split.map(&:to_i) break if n == 0 s, ans = gets.split.map(&:to_i), "Yes" n.times do b = gets.split.map(&:to_i) k.times do |i| s[i] -= b[i] ans = "No" if s[i] < 0 end end puts ans end
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22]]
4
85
while gets n,k = $_.split.map(&:to_i) break if n == 0 l = gets.split.to_a.map(&:to_i) n.times do m = gets.split.to_a.map(&:to_i) k.times do |i| l[i] -= m[i] end end puts l.all?{|i| i >= 0} ? "yes" : "no" end
while gets n,k = $_.split.map(&:to_i) break if n == 0 l = gets.split.to_a.map(&:to_i) n.times do m = gets.split.to_a.map(&:to_i) k.times do |i| l[i] -= m[i] end end puts l.all?{|i| i >= 0} ? "Yes" : "No" end
[["-", 0, 652, 3, 4, 0, 754, 64, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 754, 64, 557, 0, 6], ["-", 0, 652, 3, 4, 0, 754, 75, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 754, 75, 557, 0, 6]]
4
89
loop{ n,k = gets.split.map(&:to_i) if n == 0 and k == 0 then break end s = gets.split.map(&:to_i) n.times do s = gets.split.each_with_index.map{|b,i| (s[i] - b.to_i())} end print s.all?{|a| a >= 0} ? "YES" : "NO" print "\n" }
loop{ n,k = gets.split.map(&:to_i) if n == 0 and k == 0 then break end s = gets.split.map(&:to_i) n.times do s = gets.split.each_with_index.map{|b,i| (s[i] - b.to_i())} end print s.all?{|a| a >= 0} ? "Yes" : "No" print "\n" }
[["-", 0, 652, 3, 4, 0, 754, 64, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 754, 64, 557, 0, 6], ["-", 0, 652, 3, 4, 0, 754, 75, 557, 0, 6], ["+", 0, 652, 3, 4, 0, 754, 75, 557, 0, 6]]
4
95
import java.awt.geom.*; import java.io.*; import java.math.*; import java.util.*; public class Main { static int[] vx = new int[] {0, 1, 0, -1}; static int[] vy = new int[] {1, 0, -1, 0}; static int[] Y = new int[] {0, 0, 0, 1, 1, 1, 2, 2, 2}; static int[] X = new int[] {0, 1, 2, 0, 1, 2, 0, 1, 2}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) break; char s = sc.next().charAt(0); int S = s - 'A'; char t = sc.next().charAt(0); int T = t - 'A'; char b = sc.next().charAt(0); int B = b - 'A'; int[][][] dp = new int[n + 1][3][3]; dp[0][Y[S]][X[S]] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 4; l++) { int ty = j + vy[l]; int tx = k + vx[l]; if (ty < 0 || tx < 0 || tx >= 3 || ty >= 3 || (ty == Y[B] && tx == X[B])) { ty = j; tx = k; } dp[i + 1][ty][tx] += dp[i][j][k]; } } } } int sum = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { sum += dp[n][i][j]; } } System.out.printf("%.25f", dp[n][Y[T]][X[T]] / (double)sum); } } }
import java.awt.geom.*; import java.io.*; import java.math.*; import java.util.*; public class Main { static int[] vx = new int[] {0, 1, 0, -1}; static int[] vy = new int[] {1, 0, -1, 0}; static int[] Y = new int[] {0, 0, 0, 1, 1, 1, 2, 2, 2}; static int[] X = new int[] {0, 1, 2, 0, 1, 2, 0, 1, 2}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { int n = sc.nextInt(); if (n == 0) break; char s = sc.next().charAt(0); int S = s - 'A'; char t = sc.next().charAt(0); int T = t - 'A'; char b = sc.next().charAt(0); int B = b - 'A'; int[][][] dp = new int[n + 1][3][3]; dp[0][Y[S]][X[S]] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 3; k++) { for (int l = 0; l < 4; l++) { int ty = j + vy[l]; int tx = k + vx[l]; if (ty < 0 || tx < 0 || tx >= 3 || ty >= 3 || (ty == Y[B] && tx == X[B])) { ty = j; tx = k; } dp[i + 1][ty][tx] += dp[i][j][k]; } } } } int sum = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { sum += dp[n][i][j]; } } System.out.printf("%.25f\n", dp[n][Y[T]][X[T]] / (double)sum); } } }
[["+", 0, 1, 0, 492, 3, 4, 0, 5, 0, 44]]
3
523
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, j) REP((i), 0, (j)) #define REP(i, j, k) for (int i = (j); (i) < (k); ++i) #define BW(a, x, b) ((a) <= (x) && (x) <= (b)) #define F first #define S second #define INF 1 << 30 typedef pair<int, int> pi; typedef pair<int, pi> pii; typedef vector<int> vi; typedef queue<int> qi; typedef long long ll; double dp[16][3][3]; int n, dx[] = {0, -1, 0, 1}, dy[] = {-1, 0, 1, 0}; char cs, ct, cb; int s, t, b; int main() { while (scanf("%d", &n) && n) { memset(dp, 0.0, sizeof(dp)); scanf("\n%c %c %c", &cs, &ct, &cb); s = cs - 'A'; t = ct - 'A'; b = cb - 'A'; // fprintf(stderr, "%c\n", cs); dp[0][s / 3][s % 3] = 1.0; rep(i, n) rep(y, 3) rep(x, 3) { if (dp[i][y][x] == 0) continue; rep(d, 4) { int ny = y + dy[d], nx = x + dx[d]; if (ny < 0 || nx < 0 || ny >= 3 || nx >= 3 || ny * 3 + nx == b) dp[i + 1][y][x] += dp[i][y][x]; else dp[i + 1][ny][nx] += dp[i][y][x] * 0.25; } } printf("%.8lf\n", dp[n][t / 3][t % 3]); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define rep(i, j) REP((i), 0, (j)) #define REP(i, j, k) for (int i = (j); (i) < (k); ++i) #define BW(a, x, b) ((a) <= (x) && (x) <= (b)) #define F first #define S second #define INF 1 << 30 typedef pair<int, int> pi; typedef pair<int, pi> pii; typedef vector<int> vi; typedef queue<int> qi; typedef long long ll; double dp[16][3][3]; int n, dx[] = {0, -1, 0, 1}, dy[] = {-1, 0, 1, 0}; char cs, ct, cb; int s, t, b; int main() { while (scanf("%d", &n) && n) { memset(dp, 0.0, sizeof(dp)); scanf("\n%c %c %c", &cs, &ct, &cb); s = cs - 'A'; t = ct - 'A'; b = cb - 'A'; // fprintf(stderr, "%c\n", cs); dp[0][s / 3][s % 3] = 1.0; rep(i, n) rep(y, 3) rep(x, 3) { if (dp[i][y][x] == 0) continue; rep(d, 4) { int ny = y + dy[d], nx = x + dx[d]; if (ny < 0 || nx < 0 || ny >= 3 || nx >= 3 || ny * 3 + nx == b) dp[i + 1][y][x] += dp[i][y][x] * 0.25; else dp[i + 1][ny][nx] += dp[i][y][x] * 0.25; } } printf("%.8lf\n", dp[n][t / 3][t % 3]); } return 0; }
[["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 48], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 13]]
1
423
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <string> using namespace std; typedef long double ld; const int EMPTY = 0; const int BATTERY = 1; const int STORE = 2; const int WALL = 3; struct Point { public: int x, y; Point() {} Point(int x, int y) : x(x), y(y) {} }; struct State { public: Point p; int battery; State(){}; State(Point p, int battery) : p(p), battery(battery) {} }; Point int2point(int n) { return Point(1 + n % 3, 1 + n / 3); } int field[5][5]; double dp[16][5][5]; int main() { int n, s, t, b; while (true) { cin >> n; if (n == 0) break; char cs, ct, cb; cin >> cs >> ct >> cb; s = cs - 'A'; t = ct - 'A'; b = cb - 'A'; memset(field, EMPTY, sizeof(field)); memset(dp, 0, sizeof(dp)); for (int i = 0; i < 5; i++) { field[0][i] = WALL; field[4][i] = WALL; field[i][0] = WALL; field[4][i] = WALL; } Point batteryPoint = int2point(t); field[batteryPoint.x][batteryPoint.y] = BATTERY; Point storePoint = int2point(b); field[storePoint.x][storePoint.y] = STORE; State nowState(int2point(s), n); dp[0][nowState.p.x][nowState.p.y] = 1.0f; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; for (int i = 0; i < nowState.battery; i++) { for (int j = 1; j <= 3; j++) { for (int k = 1; k <= 3; k++) { for (int l = 0; l < 4; l++) { int nx = j + dx[l], ny = k + dy[l]; if (field[nx][ny] == STORE || field[nx][ny] == WALL) { nx = j, ny = k; } dp[i + 1][nx][ny] += dp[i][j][k] / 4.0; } } } } printf("%.20f\n", dp[nowState.battery][batteryPoint.x][batteryPoint.y]); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <string> using namespace std; typedef long double ld; const int EMPTY = 0; const int BATTERY = 1; const int STORE = 2; const int WALL = 3; struct Point { public: int x, y; Point() {} Point(int x, int y) : x(x), y(y) {} }; struct State { public: Point p; int battery; State(){}; State(Point p, int battery) : p(p), battery(battery) {} }; Point int2point(int n) { return Point(1 + n % 3, 1 + n / 3); } int field[5][5]; ld dp[16][5][5]; int main() { int n, s, t, b; while (true) { cin >> n; if (n == 0) break; char cs, ct, cb; cin >> cs >> ct >> cb; s = cs - 'A'; t = ct - 'A'; b = cb - 'A'; memset(field, EMPTY, sizeof(field)); memset(dp, 0, sizeof(dp)); for (int i = 0; i < 5; i++) { field[0][i] = WALL; field[4][i] = WALL; field[i][0] = WALL; field[i][4] = WALL; } Point batteryPoint = int2point(t); field[batteryPoint.x][batteryPoint.y] = BATTERY; Point storePoint = int2point(b); field[storePoint.x][storePoint.y] = STORE; State nowState(int2point(s), n); dp[0][nowState.p.x][nowState.p.y] = 1.0f; int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; for (int i = 0; i < nowState.battery; i++) { for (int j = 1; j <= 3; j++) { for (int k = 1; k <= 3; k++) { for (int l = 0; l < 4; l++) { int nx = j + dx[l], ny = k + dy[l]; if (field[nx][ny] == STORE || field[nx][ny] == WALL) { nx = j, ny = k; } dp[i + 1][nx][ny] += dp[i][j][k] / 4.0; } } } } printf("%.15llf\n", dp[nowState.battery][batteryPoint.x][batteryPoint.y]); } return 0; }
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 78], ["-", 0, 11, 31, 69, 28, 69, 341, 342, 0, 13], ["+", 0, 11, 31, 69, 28, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
594
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; pii get_pos(int x) { return pii(x / 3, x % 3); } bool inField(int x, int y) { return (0 <= x && x < 3 && 0 <= y && y < 3); } int main() { int N; while (cin >> N, N) { string S = "ABCDEFGHI"; char a[3]; for (int i = 0; i < 3; i++) { cin >> a[i]; } int s = S.find(a[0]); int t = S.find(a[1]); int b = S.find(a[2]); double dp[25][9] = {{}}; pii p = get_pos(b); dp[0][s] = 1; const int di[] = {-1, +0, +1, +0}; const int dj[] = {+0, -1, +0, +1}; for (int i = 0; i < N; i++) { for (int j = 0; j < 9; j++) { if (dp[i][j] == 0) continue; pii n = get_pos(j); for (int k = 0; k < 4; k++) { int ni = n.first + di[k]; int nj = n.second + dj[k]; if (!inField(nj, ni) || (pii(ni, nj) == p)) { dp[i + 1][j] += dp[i][j]; } else { dp[i + 1][ni * 3 + nj] += dp[i][j] / 4; } } } } printf("%.10f\n", dp[N][t]); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; pii get_pos(int x) { return pii(x / 3, x % 3); } bool inField(int x, int y) { return (0 <= x && x < 3 && 0 <= y && y < 3); } int main() { int N; while (cin >> N, N) { string S = "ABCDEFGHI"; char a[3]; for (int i = 0; i < 3; i++) { cin >> a[i]; } int s = S.find(a[0]); int t = S.find(a[1]); int b = S.find(a[2]); double dp[25][9] = {{}}; pii p = get_pos(b); dp[0][s] = 1; const int di[] = {-1, +0, +1, +0}; const int dj[] = {+0, -1, +0, +1}; for (int i = 0; i < N; i++) { for (int j = 0; j < 9; j++) { if (dp[i][j] == 0) continue; pii n = get_pos(j); for (int k = 0; k < 4; k++) { int ni = n.first + di[k]; int nj = n.second + dj[k]; if (!inField(nj, ni) || (pii(ni, nj) == p)) { dp[i + 1][j] += dp[i][j] / 4; } else { dp[i + 1][ni * 3 + nj] += dp[i][j] / 4; } } } } printf("%.10f\n", dp[N][t]); } return 0; }
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 85], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
404
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; int main() { int N; while (cin >> N, N) { char s, t, b; cin >> s >> t >> b; int sx, sy; sx = (s - 'A') / 3; sy = (s - 'A') % 3; int tx, ty; tx = (t - 'A') / 3; ty = (t - 'A') % 3; int bx, by; bx = (b - 'A') / 3; by = (b - 'A') % 3; vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(3, vector<int>(3, 0))); dp[0][sx][sy] = 1; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; for (int i = 0; i < N; i++) { for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int j = 0; j < 4; j++) { int nx = x + dx[j]; int ny = y + dy[j]; if (0 <= nx && nx < 3 && 0 <= ny && ny < 3) { if (x == bx && y == by) dp[i + 1][x][y] += dp[i][x][y]; else dp[i + 1][nx][ny] += dp[i][x][y]; } else { dp[i + 1][x][y] += dp[i][x][y]; } } } } } double ans = 0.; double p = 1.; for (int i = 1; i <= N; i++) { p /= 4.; } ans = p * dp[N][tx][ty]; printf("%0.9f\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; int main() { int N; while (cin >> N, N) { char s, t, b; cin >> s >> t >> b; int sx, sy; sx = (s - 'A') / 3; sy = (s - 'A') % 3; int tx, ty; tx = (t - 'A') / 3; ty = (t - 'A') % 3; int bx, by; bx = (b - 'A') / 3; by = (b - 'A') % 3; vector<vector<vector<int>>> dp(N + 1, vector<vector<int>>(3, vector<int>(3, 0))); dp[0][sx][sy] = 1; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; for (int i = 0; i < N; i++) { for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { for (int j = 0; j < 4; j++) { int nx = x + dx[j]; int ny = y + dy[j]; if (0 <= nx && nx < 3 && 0 <= ny && ny < 3) { if (nx == bx && ny == by) dp[i + 1][x][y] += dp[i][x][y]; else dp[i + 1][nx][ny] += dp[i][x][y]; } else { dp[i + 1][x][y] += dp[i][x][y]; } } } } } double ans = 0.; double p = 1.; for (int i = 1; i <= N; i++) { p /= 4.; } ans = p * dp[N][tx][ty]; printf("%0.9f\n", ans); } return 0; }
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22]]
1
465
#include <iostream> using namespace std; string intersection(string tree1, string tree2); string tunion(string tree1, string tree2); int camma_pos(string tree); int camma_pos(string tree) { int i, camma_p; int braket = 0; for (i = 0; i < tree.size(); i++) { if (tree[i] == '(') { braket++; } else if (tree[i] == ')') { braket--; } if ((tree[i] == ',') && (braket == 1)) { camma_p = i; } } return camma_p; } string intersection(string tree1, string tree2) { int i; int braket = 0; int camma_p1, camma_p2; string tree1_l, tree1_r; string tree2_l, tree2_r; string left, right; if (tree1.size() == 0 || tree2.size() == 0) { return ""; } camma_p1 = camma_pos(tree1); camma_p2 = camma_pos(tree2); tree1_l = tree1.substr(1, camma_p1 - 1); tree1_r = tree1.substr(camma_p1 + 1, tree1.size() - camma_p1 - 2); tree2_l = tree2.substr(1, camma_p2 - 1); tree2_r = tree2.substr(camma_p2 + 1, tree2.size() - camma_p2 - 2); left = intersection(tree1_l, tree2_l); right = intersection(tree1_r, tree2_r); return "(" + left + "," + right + ")"; } string tunion(string tree1, string tree2) { int i; int braket = 0; int camma_p1, camma_p2; string tree1_l, tree1_r; string tree2_l, tree2_r; string left, right; if (tree1.size() == 0) { return tree2; } if (tree2.size() == 0) { return tree1; } camma_p1 = camma_pos(tree1); camma_p2 = camma_pos(tree2); tree1_l = tree1.substr(1, camma_p1 - 1); tree1_r = tree1.substr(camma_p1 + 1, tree1.size() - camma_p1 - 2); tree2_l = tree2.substr(1, camma_p2 - 1); tree2_r = tree2.substr(camma_p2 + 1, tree2.size() - camma_p2 - 2); left = tunion(tree1_l, tree2_l); right = tunion(tree1_r, tree2_r); return "(" + left + "," + right + ")"; } int main() { char ui; string tree1, tree2, treeans; cin >> ui >> tree1 >> tree2; if (ui == 'i') { treeans = intersection(tree1, tree2); } else { treeans = tunion(tree1, tree2); } cout << treeans << endl; }
#include <iostream> using namespace std; string intersection(string tree1, string tree2); string tunion(string tree1, string tree2); int camma_pos(string tree); int camma_pos(string tree) { int i, camma_p; int braket = 0; for (i = 0; i < tree.size(); i++) { if (tree[i] == '(') { braket++; } else if (tree[i] == ')') { braket--; } if ((tree[i] == ',') && (braket == 1)) { camma_p = i; } } return camma_p; } string intersection(string tree1, string tree2) { int i; int braket = 0; int camma_p1, camma_p2; string tree1_l, tree1_r; string tree2_l, tree2_r; string left, right; if (tree1.size() == 0 || tree2.size() == 0) { return ""; } camma_p1 = camma_pos(tree1); camma_p2 = camma_pos(tree2); tree1_l = tree1.substr(1, camma_p1 - 1); tree1_r = tree1.substr(camma_p1 + 1, tree1.size() - camma_p1 - 2); tree2_l = tree2.substr(1, camma_p2 - 1); tree2_r = tree2.substr(camma_p2 + 1, tree2.size() - camma_p2 - 2); left = intersection(tree1_l, tree2_l); right = intersection(tree1_r, tree2_r); return "(" + left + "," + right + ")"; } string tunion(string tree1, string tree2) { int i; int braket = 0; int camma_p1, camma_p2; string tree1_l, tree1_r; string tree2_l, tree2_r; string left, right; if (tree1.size() == 0) { return tree2; } if (tree2.size() == 0) { return tree1; } camma_p1 = camma_pos(tree1); camma_p2 = camma_pos(tree2); tree1_l = tree1.substr(1, camma_p1 - 1); tree1_r = tree1.substr(camma_p1 + 1, tree1.size() - camma_p1 - 2); tree2_l = tree2.substr(1, camma_p2 - 1); tree2_r = tree2.substr(camma_p2 + 1, tree2.size() - camma_p2 - 2); left = tunion(tree1_l, tree2_l); right = tunion(tree1_r, tree2_r); return "(" + left + "," + right + ")"; } int main() { char ui; string tree1, tree2, treeans; while (cin >> ui >> tree1 >> tree2) { if (ui == 'i') { treeans = intersection(tree1, tree2); } else { treeans = tunion(tree1, tree2); } cout << treeans << endl; } }
[["+", 0, 30, 0, 14, 8, 9, 0, 52, 0, 89], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 24], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 52, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 45], ["+", 0, 14, 8, 9, 0, 52, 8, 9, 0, 46]]
1
558
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() const double PI = acos(-1); const double EPS = 1e-10; const int inf = 1e9; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; int main() { int q; cin >> q; while (q--) { int n, N; cin >> n; N = n * 2; string s; cin >> s; rep(i, s.size()) s[i] = (s[i] == 'Y' ? 1 : 0); string t = s.substr(N); s = s.substr(0, N); vvi dp(n + 1, vi(2, inf)); if (t[0]) dp[0][1] = 2; else if (s[0]) { dp[0][1] = 1; dp[0][0] = 1; } else dp[0][0] = 0; rep(i, n) { int a, b; if (i != n - 1) { a = s[i * 2 + 2] || s[i * 2 + 1]; b = t[i * 2 + 2] || t[i * 2 + 1]; } else { a = s[i * 2 + 1]; b = t[i * 2 + 1]; } if (dp[i][0] != inf) { if (b) dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + 2); else if (a) { dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + 1); dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + 1); } else dp[i + 1][0] = min(dp[i + 1][0], dp[i][0]); } if (dp[i][1] != inf) { if (a + b == 2) { dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 2); dp[i + 1][0] = min(dp[1 + 1][0], dp[i][1] + 2); } else if (a + b == 0) dp[i + 1][1] = min(dp[i + 1][1], dp[i][1]); else if (a) { dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 1); dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + 1); } else if (b) dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 1); } } cout << min(dp[n][0], dp[n][1] + 1) + n << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <utility> #include <vector> #define loop(i, a, b) for (int i = a; i < b; i++) #define rep(i, a) loop(i, 0, a) #define pb push_back #define mp make_pair #define all(in) in.begin(), in.end() const double PI = acos(-1); const double EPS = 1e-10; const int inf = 1e9; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; int main() { int q; cin >> q; while (q--) { int n, N; cin >> n; N = n * 2; string s; cin >> s; rep(i, s.size()) s[i] = (s[i] == 'Y' ? 1 : 0); string t = s.substr(N); s = s.substr(0, N); vvi dp(n + 1, vi(2, inf)); if (t[0]) dp[0][1] = 2; else if (s[0]) { dp[0][1] = 1; dp[0][0] = 1; } else dp[0][0] = 0; rep(i, n) { int a, b; if (i != n - 1) { a = s[i * 2 + 2] || s[i * 2 + 1]; b = t[i * 2 + 2] || t[i * 2 + 1]; } else { a = s[i * 2 + 1]; b = t[i * 2 + 1]; } if (dp[i][0] != inf) { if (b) dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + 2); else if (a) { dp[i + 1][1] = min(dp[i + 1][1], dp[i][0] + 1); dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + 1); } else dp[i + 1][0] = min(dp[i + 1][0], dp[i][0]); } if (dp[i][1] != inf) { if (a + b == 2) { dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 2); dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + 2); } else if (a + b == 0) dp[i + 1][1] = min(dp[i + 1][1], dp[i][1]); else if (a) { dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 1); dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + 1); } else if (b) dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 1); } } cout << min(dp[n][0], dp[n][1] + 1) + n << endl; } }
[["-", 0, 69, 28, 69, 341, 342, 0, 16, 31, 13], ["+", 0, 69, 28, 69, 341, 342, 0, 16, 31, 22]]
1
785
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) using namespace std; int dp[100005][3]; void solve(string s1, string s2) { memset(dp, 0, sizeof(dp)); dp[0][0] = 0; dp[0][1] = 1000; dp[0][2] = 1000; for (int i = 0; i < s1.size(); i += 2) { if ((s1[i] == 'Y' || s1[i + 1] == 'Y') && (s2[i] == 'Y' || s2[i + 1] == 'Y')) { dp[i + 2][0] = min(dp[i][0] + 3, min(dp[i][1] + 2, dp[i][2] + 2)) + 1; dp[i + 2][1] = min(dp[i][0] + 2, min(dp[i][1] + 2, dp[i][2] + 2)) + 1; dp[i + 2][2] = min(dp[i][0] + 2, min(dp[i][1] + 2, dp[i][2] + 3)) + 1; } else if (s1[i] == 'Y' || s1[i + 1] == 'Y') { dp[i + 2][2] = min(dp[i][0] + 2, min(dp[i][1] + 2, dp[i][2] + 3)) + 1; dp[i + 2][1] = min(dp[i][0] + 1, min(dp[i][1] + 1, dp[i][2] + 1)) + 1; dp[i + 2][0] = min(dp[i][0] + 1, min(dp[i][1] + 1, dp[i][2] + 1)) + 1; } else if (s2[i] == 'Y' || s2[i + 1] == 'Y') { dp[i + 2][0] = min(dp[i][0] + 3, min(dp[i][1] + 2, dp[i][2] + 2)) + 1; dp[i + 2][1] = min(dp[i][0] + 1, min(dp[i][1] + 1, dp[i][2] + 1)) + 1; dp[i + 2][2] = min(dp[i][0] + 1, min(dp[i][1] + 1, dp[i][2] + 1)) + 1; } else { dp[i + 2][0] = min(dp[i][0], min(dp[i][1] + 1, dp[i][2] + 2)) + 1; dp[i + 2][1] = min(dp[i][0] + 1, min(dp[i][1], dp[i][2] + 1)) + 1; dp[i + 2][2] = min(dp[i][0] + 2, min(dp[i][1] + 1, dp[i][2])) + 1; } } cout << dp[s1.size()][0] - 1 << endl; } void sol() { int n; cin >> n; string tmp, s1, s2; cin >> tmp; s1 = "N" + tmp.substr(0, n * 2) + "N"; s2 = "N" + tmp.substr(n * 2) + "N"; solve(s1, s2); } int main() { int TEST; cin >> TEST; while (TEST--) sol(); }
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) using namespace std; int dp[100005][3]; void solve(string s1, string s2) { memset(dp, 0, sizeof(dp)); dp[0][0] = 0; dp[0][1] = 1000; dp[0][2] = 1000; for (int i = 0; i < s1.size(); i += 2) { if ((s1[i] == 'Y' || s1[i + 1] == 'Y') && (s2[i] == 'Y' || s2[i + 1] == 'Y')) { dp[i + 2][0] = min(dp[i][0] + 3, min(dp[i][1] + 2, dp[i][2] + 2)) + 1; dp[i + 2][1] = min(dp[i][0] + 2, min(dp[i][1] + 2, dp[i][2] + 2)) + 1; dp[i + 2][2] = min(dp[i][0] + 2, min(dp[i][1] + 2, dp[i][2] + 3)) + 1; } else if (s1[i] == 'Y' || s1[i + 1] == 'Y') { dp[i + 2][2] = min(dp[i][0] + 2, min(dp[i][1] + 2, dp[i][2] + 3)) + 1; dp[i + 2][1] = min(dp[i][0] + 1, min(dp[i][1] + 1, dp[i][2] + 2)) + 1; dp[i + 2][0] = min(dp[i][0] + 1, min(dp[i][1] + 1, dp[i][2] + 2)) + 1; } else if (s2[i] == 'Y' || s2[i + 1] == 'Y') { dp[i + 2][0] = min(dp[i][0] + 3, min(dp[i][1] + 2, dp[i][2] + 2)) + 1; dp[i + 2][1] = min(dp[i][0] + 2, min(dp[i][1] + 1, dp[i][2] + 1)) + 1; dp[i + 2][2] = min(dp[i][0] + 2, min(dp[i][1] + 1, dp[i][2] + 1)) + 1; } else { dp[i + 2][0] = min(dp[i][0], min(dp[i][1] + 1, dp[i][2] + 2)) + 1; dp[i + 2][1] = min(dp[i][0] + 1, min(dp[i][1], dp[i][2] + 1)) + 1; dp[i + 2][2] = min(dp[i][0] + 2, min(dp[i][1] + 1, dp[i][2])) + 1; } } cout << dp[s1.size()][0] - 1 << endl; } void sol() { int n; cin >> n; string tmp, s1, s2; cin >> tmp; s1 = "N" + tmp.substr(0, n * 2) + "N"; s2 = "N" + tmp.substr(n * 2) + "N"; solve(s1, s2); } int main() { int TEST; cin >> TEST; while (TEST--) sol(); }
[["-", 3, 4, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 3, 4, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 12, 16, 31, 2, 3, 4, 0, 16, 12, 13], ["+", 12, 16, 31, 2, 3, 4, 0, 16, 12, 13]]
1
879
#include <algorithm> #include <iostream> using namespace std; const int INF = 100000000; int n, dp[3][10002], t; bool input[2][10002]; int cost[3][3][4] = {{{1, 2, 4, 4}, {2, 2, 3, 3}, {3, 3, 3, 3}}, {{2, 2, 3, 3}, {1, 2, 2, 3}, {2, 3, 2, 3}}, {{3, 3, 3, 3}, {2, 3, 2, 3}, {1, 4, 2, 4}}}; main() { cin >> t; while (t--) { cin >> n; fill(input[0], input[2], false); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2 * n; j++) { char c; cin >> c; if (c == 'Y') input[i][(j + 1) / 2] = true; } } fill(dp[0], dp[3], INF); for (int i = 0; i < 3; i++) dp[i][0] = i; for (int j = 0; j <= n; j++) { for (int i = 0; i < 3; i++) { int s; if (input[0][j] && input[1][j]) s = 3; else if (input[0][j]) s = 1; else if (input[1][j]) s = 2; else s = 0; for (int k = 0; k < 3; k++) { dp[k][j + 1] = min(dp[k][j + 1], dp[i][j] + cost[i][k][s]); } } } cout << dp[0][n + 1] << endl; } }
#include <algorithm> #include <iostream> using namespace std; const int INF = 100000000; int n, dp[3][10002], t; bool input[2][10002]; int cost[3][3][4] = {{{1, 2, 4, 4}, {2, 2, 3, 3}, {3, 3, 3, 3}}, {{2, 2, 3, 3}, {1, 2, 2, 3}, {2, 3, 2, 3}}, {{3, 3, 3, 3}, {2, 3, 2, 3}, {1, 4, 2, 4}}}; main() { cin >> t; while (t--) { cin >> n; fill(input[0], input[2], false); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2 * n; j++) { char c; cin >> c; if (c == 'Y') input[i][(j + 1) / 2] = true; } } fill(dp[0], dp[3], INF); for (int i = 0; i < 3; i++) dp[i][0] = i; for (int j = 0; j <= n; j++) { for (int i = 0; i < 3; i++) { int s; if (input[0][j] && input[1][j]) s = 3; else if (input[0][j]) s = 1; else if (input[1][j]) s = 2; else s = 0; for (int k = 0; k < 3; k++) { dp[k][j + 1] = min(dp[k][j + 1], dp[i][j] + cost[i][k][s]); } } } cout << dp[0][n + 1] - 1 << endl; } }
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
449
#include <iostream> #include <vector> using namespace std; void solve() { int n; cin >> n; string s[2]; { string t; cin >> t; s[0] = 'N' + t.substr(0, 2 * n) + 'N'; s[1] = 'N' + t.substr(2 * n) + 'N'; } vector<vector<int>> dp(2, vector<int>(n + 1)); if (s[1][0] == 'Y') { dp[0][0] = 3; dp[1][0] = 2; } else if (s[0][0] == 'Y') dp[0][0] = dp[1][0] = 1; else dp[1][0] = 1; for (int i = 1; i <= n; i++) { if ((s[0][i * 2] == 'Y' || s[0][i * 2 + 1] == 'Y') && (s[1][i * 2] == 'Y' || s[1][i * 2 + 1] == 'Y')) { dp[0][i] = min(dp[0][i - 1] + 3, dp[1][i - 1] + 2); dp[1][i] = min(dp[0][i - 1] + 2, dp[1][i - 1] + 2); } else if (s[1][i * 2] == 'Y' || s[1][i * 2 + 1] == 'Y') { dp[0][i] = min(dp[0][i - 1] + 3, dp[1][i - 1] + 2); dp[1][i] = min(dp[0][i - 1] + 2, dp[1][i - 1] + 1); } else if (s[0][i * 2] == 'Y' || s[0][i * 2 + 1] == 'Y') { dp[0][i] = min(dp[0][i - 1] + 1, dp[1][i - 1] + 1); dp[1][i] = min(dp[0][i - 1] + 1, dp[1][i - 1] + 1); } else { dp[0][i] = min(dp[0][i - 1], dp[1][i - 1] + 1); dp[1][i] = min(dp[0][i - 1] + 1, dp[1][i - 1]); } dp[0][i]++; dp[1][i]++; } cout << dp[0][n] << endl; } int main() { int tc; cin >> tc; while (tc--) solve(); return 0; }
#include <iostream> #include <vector> using namespace std; void solve() { int n; cin >> n; string s[2]; { string t; cin >> t; s[0] = 'N' + t.substr(0, 2 * n) + 'N'; s[1] = 'N' + t.substr(2 * n) + 'N'; } vector<vector<int>> dp(2, vector<int>(n + 1)); if (s[1][1] == 'Y') { dp[0][0] = 3; dp[1][0] = 2; } else if (s[0][1] == 'Y') dp[0][0] = dp[1][0] = 1; else dp[1][0] = 1; for (int i = 1; i <= n; i++) { if ((s[0][i * 2] == 'Y' || s[0][i * 2 + 1] == 'Y') && (s[1][i * 2] == 'Y' || s[1][i * 2 + 1] == 'Y')) { dp[0][i] = min(dp[0][i - 1] + 3, dp[1][i - 1] + 2); dp[1][i] = min(dp[0][i - 1] + 2, dp[1][i - 1] + 2); } else if (s[1][i * 2] == 'Y' || s[1][i * 2 + 1] == 'Y') { dp[0][i] = min(dp[0][i - 1] + 3, dp[1][i - 1] + 2); dp[1][i] = min(dp[0][i - 1] + 2, dp[1][i - 1] + 1); } else if (s[0][i * 2] == 'Y' || s[0][i * 2 + 1] == 'Y') { dp[0][i] = min(dp[0][i - 1] + 1, dp[1][i - 1] + 1); dp[1][i] = min(dp[0][i - 1] + 1, dp[1][i - 1] + 1); } else { dp[0][i] = min(dp[0][i - 1], dp[1][i - 1] + 1); dp[1][i] = min(dp[0][i - 1] + 1, dp[1][i - 1]); } dp[0][i]++; dp[1][i]++; } cout << dp[0][n] << endl; } int main() { int tc; cin >> tc; while (tc--) solve(); return 0; }
[["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13]]
1
672
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; int main() { int q; cin >> q; for (int loop = 0; loop < q; loop++) { int n; string str; cin >> n; cin >> str; vector<vector<bool>> field(2, vector<bool>(n + 1, false)); for (int i = 0; i < 2 + n; i++) { if (str[i] == 'Y') { field[0][(i + 1) / 2] = true; } if (str[i + 2 * n] == 'Y') { field[1][(i + 1) / 2] = true; } } int ans = n; bool first = true; int b_s = 0; for (int i = 0; i < n + 1; i++) { if (first) { if (field[1][i]) { first = false; ans += 2; b_s = 1; } else if (field[0][i]) { first = false; ans++; } } else { if (field[0][i] && field[1][i]) { ans += 2; b_s = 0; } else if (field[0][i]) { ans++; b_s = 0; } else if (field[1][i]) { ans++; b_s = 1; } } } if (b_s == 1) ans++; cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; int main() { int q; cin >> q; for (int loop = 0; loop < q; loop++) { int n; string str; cin >> n; cin >> str; vector<vector<bool>> field(2, vector<bool>(n + 1, false)); for (int i = 0; i < 2 * n; i++) { if (str[i] == 'Y') { field[0][(i + 1) / 2] = true; } if (str[i + 2 * n] == 'Y') { field[1][(i + 1) / 2] = true; } } int ans = n; bool first = true; int b_s = 0; for (int i = 0; i < n + 1; i++) { if (first) { if (field[1][i]) { first = false; ans += 2; b_s = 1; } else if (field[0][i]) { first = false; ans++; } } else { if (field[0][i] && field[1][i]) { ans += 2; b_s = 0; } else if (field[0][i]) { ans++; b_s = 0; } else if (field[1][i]) { ans++; b_s = 1; } } } if (b_s == 1) ans++; cout << ans << endl; } return 0; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 48]]
1
335
pre = [ ((0, 1, 2), (1, 0, 1), (2, 1, 0)), ((3, 2, 2), (2, 1, 1), (2, 1, 1)), ((1, 1, 2), (1, 1, 2), (2, 2, 3)), ((3, 2, 2), (2, 2, 2), (2, 2, 3)), ] q = int(input()) for _ in range(q): n = int(input()) books = [c == 'Y' for c in input()] books = [(False, False)] + list(map(lambda u, l: (u, l), books[:2 * n], books[2 * n:])) + [(False, False)] shelves = [int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)] ans = [0, 0, 0] for key in shelves: new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]] ans = new_ans print(ans[0] + n)
pre = [ ((0, 1, 2), (1, 0, 1), (2, 1, 0)), ((3, 2, 2), (2, 1, 1), (2, 1, 1)), ((1, 1, 2), (1, 1, 2), (2, 2, 3)), ((3, 2, 2), (2, 2, 2), (2, 2, 3)), ] q = int(input()) for _ in range(q): n = int(input()) books = [c == 'Y' for c in input()] books = [(False, False)] + list(map(lambda u, l: (u, l), books[:2 * n], books[2 * n:])) + [(False, False)] shelves = [int(u1 or u2) * 2 + int(l1 or l2) for (u1, l1), (u2, l2) in zip(*[iter(books)] * 2)] ans = [0, 1, 2] for key in shelves: new_ans = [min(a + c for a, c in zip(ans, costs)) for costs in pre[key]] ans = new_ans print(ans[0] + n)
[["-", 8, 196, 0, 1, 0, 662, 12, 634, 0, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 634, 0, 612]]
5
295
import java.util.Scanner; public class Main { String str[][] = {{" "}, {"'", ",", ".", "!", "?"}, {"a", "b", "c", "A", "B", "C"}, {"d", "e", "f", "D", "E", "F"}, {"g", "h", "i", "G", "H", "I"}, {"j", "k", "l", "J", "K", "L"}, {"m", "n", "o", "M", "N", "O"}, {"p", "q", "r", "s", "P", "Q", "R", "S"}, {"t", "u", "v", "T", "U", "V"}, {"w", "x", "y", "z", "W", "X", "Y", "Z"}}; public Main() { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String st = sc.next(); int n = st.length(); for (int i = 0; i < n - 1;) { String s = st.substring(i, i + 1); int t = Integer.parseInt(s); int c = 0; int l = str[t].length; i++; if (s.equals("0")) { for (; i <= n - 1 && s.equals(st.substring(i, i + 1)); i++, c++) { System.out.print(" "); } } else { for (; i <= n - 1 && s.equals(st.substring(i, i + 1)); i++, c++) ; System.out.print(str[t][c % l]); } } System.out.println(); } } public static void main(String[] args) { new Main(); } }
import java.util.Scanner; public class Main { String str[][] = {{" "}, {"'", ",", ".", "!", "?"}, {"a", "b", "c", "A", "B", "C"}, {"d", "e", "f", "D", "E", "F"}, {"g", "h", "i", "G", "H", "I"}, {"j", "k", "l", "J", "K", "L"}, {"m", "n", "o", "M", "N", "O"}, {"p", "q", "r", "s", "P", "Q", "R", "S"}, {"t", "u", "v", "T", "U", "V"}, {"w", "x", "y", "z", "W", "X", "Y", "Z"}}; public Main() { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String st = sc.next(); int n = st.length(); for (int i = 0; i < n;) { String s = st.substring(i, i + 1); int t = Integer.parseInt(s); int c = 0; int l = str[t].length; i++; if (s.equals("0")) { for (; i <= n - 1 && s.equals(st.substring(i, i + 1)); i++, c++) { System.out.print(" "); } } else { for (; i <= n - 1 && s.equals(st.substring(i, i + 1)); i++, c++) ; System.out.print(str[t][c % l]); } } System.out.println(); } } public static void main(String[] args) { new Main(); } }
[["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 33], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 499]]
3
510
import java.util.Scanner; class Main { private static void solve() { final Scanner scanner = new Scanner(System.in); final char[][] keymap = {null, {',', ',', '.', '!', '?'}, {'a', 'b', 'c', 'A', 'B', 'A'}, {'d', 'e', 'f', 'D', 'E', 'F'}, {'g', 'h', 'i', 'G', 'H', 'I'}, {'j', 'k', 'l', 'J', 'K', 'L'}, {'m', 'n', 'o', 'M', 'N', 'O'}, {'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S'}, {'t', 'u', 'v', 'T', 'U', 'V'}, {'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z'}}; while (scanner.hasNext()) { final char[] line = scanner.next().toCharArray(); int index = 0; while (index != line.length) { final char digit = line[index]; int counter = 1; while (++index < line.length && line[index] == digit) { counter++; } if (keymap[digit - '0'] == null) { for (int i = 1; i < counter; i++) { System.out.print(' '); } } else { final int length = keymap[digit - '0'].length; System.out.print(keymap[digit - '0'][(counter - 1) % length]); } } System.out.println(); } } public static void main(String... args) { solve(); } }
import java.util.Scanner; class Main { private static void solve() { final Scanner scanner = new Scanner(System.in); final char[][] keymap = {null, {'\'', ',', '.', '!', '?'}, {'a', 'b', 'c', 'A', 'B', 'C'}, {'d', 'e', 'f', 'D', 'E', 'F'}, {'g', 'h', 'i', 'G', 'H', 'I'}, {'j', 'k', 'l', 'J', 'K', 'L'}, {'m', 'n', 'o', 'M', 'N', 'O'}, {'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S'}, {'t', 'u', 'v', 'T', 'U', 'V'}, {'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z'}}; while (scanner.hasNext()) { final char[] line = scanner.next().toCharArray(); int index = 0; while (index != line.length) { final char digit = line[index]; int counter = 1; while (++index < line.length && line[index] == digit) { counter++; } if (keymap[digit - '0'] == null) { for (int i = 1; i < counter; i++) { System.out.print(' '); } } else { final int length = keymap[digit - '0'].length; System.out.print(keymap[digit - '0'][(counter - 1) % length]); } } System.out.println(); } } public static void main(String... args) { solve(); } }
[["-", 0, 503, 49, 200, 51, 518, 0, 518, 0, 252], ["+", 0, 503, 49, 200, 51, 518, 0, 518, 0, 252]]
3
351
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String one = ",,.,!?"; String two = "abcABC"; String three = "defDEF"; String four = "ghiGHI"; String five = "jklJKL"; String six = "mnoMNO"; String seven = "pqrsPQRS"; String eight = "tuvTUV"; String nine = "wxyzWXYZ"; String zero = " "; while (sc.hasNext()) { String ans = ""; String line = sc.next(); int n = 0; while (line.length() > n) { int count = 0; while (n + 1 != line.length() && line.charAt(n) == line.charAt(n + 1)) { count++; n++; } String temp = ""; if (line.charAt(n) == '1') temp = one; else if (line.charAt(n) == '2') temp = two; else if (line.charAt(n) == '3') temp = three; else if (line.charAt(n) == '4') temp = four; else if (line.charAt(n) == '5') temp = five; else if (line.charAt(n) == '6') temp = six; else if (line.charAt(n) == '7') temp = seven; else if (line.charAt(n) == '8') temp = eight; else if (line.charAt(n) == '9') temp = nine; else if (line.charAt(n) == '0') temp = zero; if (temp == zero) { if (count >= 1) { for (int k = 0; k < count; k++) { ans += " "; } } } else { ans += temp.charAt(count % temp.length()); } n++; } System.out.println(ans); } } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String one = "',.,!?"; String two = "abcABC"; String three = "defDEF"; String four = "ghiGHI"; String five = "jklJKL"; String six = "mnoMNO"; String seven = "pqrsPQRS"; String eight = "tuvTUV"; String nine = "wxyzWXYZ"; String zero = " "; while (sc.hasNext()) { String ans = ""; String line = sc.next(); int n = 0; while (line.length() > n) { int count = 0; while (n + 1 != line.length() && line.charAt(n) == line.charAt(n + 1)) { count++; n++; } String temp = ""; if (line.charAt(n) == '1') temp = one; else if (line.charAt(n) == '2') temp = two; else if (line.charAt(n) == '3') temp = three; else if (line.charAt(n) == '4') temp = four; else if (line.charAt(n) == '5') temp = five; else if (line.charAt(n) == '6') temp = six; else if (line.charAt(n) == '7') temp = seven; else if (line.charAt(n) == '8') temp = eight; else if (line.charAt(n) == '9') temp = nine; else if (line.charAt(n) == '0') temp = zero; if (temp == zero) { if (count >= 1) { for (int k = 0; k < count; k++) { ans += " "; } } } else { ans += temp.charAt(count % temp.length()); } n++; } System.out.println(ans); } } }
[["-", 8, 196, 0, 503, 49, 200, 51, 5, 0, 491], ["+", 8, 196, 0, 503, 49, 200, 51, 5, 0, 491]]
3
421
// Aizu Vol-10 1003: Extraordinary Girl II // 2017.8.18 bal4u@uu #include <stdio.h> char *gets(); char tbl[10][8] = {{0}, {'\'', ',', '.', '!', '?'}, {'a', 'b', 'c', 'A', 'B', 'C'}, {'d', 'e', 'f', 'D', 'E', 'F'}, {'g', 'h', 'i', 'G', 'H', 'I'}, {'j', 'k', 'l', 'J', 'K', 'L'}, {'m', 'n', 'o', 'M', 'N', 'O'}, {'P', 'q', 'r', 's', 'P', 'Q', 'R', 'S'}, {'t', 'u', 'v', 'T', 'U', 'V'}, {'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z'}}; int len[10] = {0, 5, 6, 6, 6, 6, 6, 8, 6, 8}; char buf[10010], *p; int main() { int d, w; char c; while (gets(p = buf) != NULL) { while (*p) { c = *p++, d = c - '0'; w = 0; while (*p == c) w++, p++; if (d == 0) while (w-- > 0) putchar(' '); else putchar(tbl[d][w % len[d]]); } putchar('\n'); } return 0; }
// Aizu Vol-10 1003: Extraordinary Girl II // 2017.8.18 bal4u@uu #include <stdio.h> char *gets(); char tbl[10][8] = {{0}, {'\'', ',', '.', '!', '?'}, {'a', 'b', 'c', 'A', 'B', 'C'}, {'d', 'e', 'f', 'D', 'E', 'F'}, {'g', 'h', 'i', 'G', 'H', 'I'}, {'j', 'k', 'l', 'J', 'K', 'L'}, {'m', 'n', 'o', 'M', 'N', 'O'}, {'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S'}, {'t', 'u', 'v', 'T', 'U', 'V'}, {'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z'}}; int len[10] = {0, 5, 6, 6, 6, 6, 6, 8, 6, 8}; char buf[10010], *p; int main() { int d, w; char c; while (gets(p = buf) != NULL) { while (*p) { c = *p++, d = c - '0'; w = 0; while (*p == c) w++, p++; if (d == 0) while (w-- > 0) putchar(' '); else putchar(tbl[d][w % len[d]]); } putchar('\n'); } return 0; }
[["-", 49, 50, 51, 83, 0, 83, 0, 103, 0, 125], ["+", 49, 50, 51, 83, 0, 83, 0, 103, 0, 125]]
0
420
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) range(i, 0, b) #define pb(a) push_back(a) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; using namespace std; int main() { string s; while (cin >> s) { char c; int count = 1; s += 'A'; rep(i, s.size() - 1) { if (s[i] == s[i + 1]) { count++; } else { if (s[i] == '1') { if (count % 5 == 1) c = '\''; else if (count % 5 == 2) c = ','; else if (count % 5 == 3) c = '.'; else if (count % 5 == 4) c = '!'; else if (count % 5 == 0) c = '?'; } else if (s[i] == '2') { if ((count - 1) % 6 < 3) c = 'a' + (count - 1) % 3; else c = 'A' + (count - 1) % 3; } else if (s[i] == '3') { if ((count - 1) % 6 < 3) c = 'd' + (count - 1) % 3; else c = 'D' + (count - 1) % 3; } else if (s[i] == '4') { if ((count - 1) % 6 < 3) c = 'g' + (count - 1) % 3; else c = 'G' + (count - 1) % 3; } else if (s[i] == '5') { if ((count - 1) % 6 < 3) c = 'j' + (count - 1) % 3; else c = 'J' + (count - 1) % 3; } else if (s[i] == '6') { if ((count - 1) % 6 < 3) c = 'm' + (count - 1) % 3; else c = 'M' + (count - 1) % 3; } else if (s[i] == '7') { if ((count - 1) % 8 < 4) c = 'p' + (count - 1) % 3; else c = 'P' + (count - 1) % 4; } else if (s[i] == '8') { if ((count - 1) % 6 < 3) c = 't' + (count - 1) % 3; else c = 'T' + (count - 1) % 3; } else if (s[i] == '9') { if ((count - 1) % 8 < 4) c = 'w' + (count - 1) % 3; else c = 'W' + (count - 1) % 4; } if (s[i] == '0') rep(i, count - 1) cout << ' '; else cout << c; count = 1; } } cout << endl; } }
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) range(i, 0, b) #define pb(a) push_back(a) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; using namespace std; int main() { string s; while (cin >> s) { char c; int count = 1; s += 'A'; rep(i, s.size() - 1) { if (s[i] == s[i + 1]) { count++; } else { if (s[i] == '1') { if (count % 5 == 1) c = '\''; else if (count % 5 == 2) c = ','; else if (count % 5 == 3) c = '.'; else if (count % 5 == 4) c = '!'; else if (count % 5 == 0) c = '?'; } else if (s[i] == '2') { if ((count - 1) % 6 < 3) c = 'a' + (count - 1) % 3; else c = 'A' + (count - 1) % 3; } else if (s[i] == '3') { if ((count - 1) % 6 < 3) c = 'd' + (count - 1) % 3; else c = 'D' + (count - 1) % 3; } else if (s[i] == '4') { if ((count - 1) % 6 < 3) c = 'g' + (count - 1) % 3; else c = 'G' + (count - 1) % 3; } else if (s[i] == '5') { if ((count - 1) % 6 < 3) c = 'j' + (count - 1) % 3; else c = 'J' + (count - 1) % 3; } else if (s[i] == '6') { if ((count - 1) % 6 < 3) c = 'm' + (count - 1) % 3; else c = 'M' + (count - 1) % 3; } else if (s[i] == '7') { if ((count - 1) % 8 < 4) c = 'p' + (count - 1) % 4; else c = 'P' + (count - 1) % 4; } else if (s[i] == '8') { if ((count - 1) % 6 < 3) c = 't' + (count - 1) % 3; else c = 'T' + (count - 1) % 3; } else if (s[i] == '9') { if ((count - 1) % 8 < 4) c = 'w' + (count - 1) % 4; else c = 'W' + (count - 1) % 4; } if (s[i] == '0') rep(i, count - 1) cout << ' '; else cout << c; count = 1; } } cout << endl; } }
[["-", 64, 1, 0, 11, 12, 16, 12, 16, 12, 13], ["+", 64, 1, 0, 11, 12, 16, 12, 16, 12, 13]]
1
675
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; string button[] = {"", "',.!?", "abcABC", "defDEF", "ghiGHI", "jklJKL", "mnoMNO", "pqrsPQRS", "ruvTUV", "wxyzWXYZ"}; char cal(int buf, int cnt) { return button[buf][cnt % button[buf].size()]; } int main() { string line; while (cin >> line) { string ans; int buf = -1, cnt = 0; for (char c : line) { int index = c - '0'; if (index == 0) { if (buf == 0) { ans += " "; } else if (buf != -1) { ans += cal(buf, cnt); buf = index; } continue; } if (buf == index) cnt++; else { if (buf > 0) ans += cal(buf, cnt); buf = index; cnt = 0; } } if (buf > 0) ans += cal(buf, cnt); cout << ans << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; string button[] = {"", "',.!?", "abcABC", "defDEF", "ghiGHI", "jklJKL", "mnoMNO", "pqrsPQRS", "tuvTUV", "wxyzWXYZ"}; char cal(int buf, int cnt) { return button[buf][cnt % button[buf].size()]; } int main() { string line; while (cin >> line) { string ans; int buf = -1, cnt = 0; for (char c : line) { int index = c - '0'; if (index == 0) { if (buf == 0) { ans += " "; } else if (buf != -1) { ans += cal(buf, cnt); buf = index; } continue; } if (buf == index) cnt++; else { if (buf > 0) ans += cal(buf, cnt); buf = index; cnt = 0; } } if (buf > 0) ans += cal(buf, cnt); cout << ans << endl; } return 0; }
[["-", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6], ["+", 0, 43, 49, 50, 51, 83, 0, 5, 0, 6]]
1
243
alpha = ["","'.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"] while True: try: ans = "" sers = "" c = 0 for key in input(): if key == "0": if len(sers) > 0: n,l = int(sers[0]),len(sers) l = (l-1)%len(alpha[n]) ans += alpha[n][l] sers = "" else: ans += " " elif len(sers) == 0 or sers[-1] == key: sers += key else: n,l = int(sers[0]),len(sers) l = (l-1)%len(alpha[n]) ans += alpha[n][l] sers = key if len(sers) > 0: if sers[0] == 0: ans += " "*len(sers) else: n,l = int(sers[0]),len(sers) l = (l-1)%len(alpha[n]) ans += alpha[n][l] print(ans) except: break
alpha = ["","',.!?","abcABC","defDEF","ghiGHI","jklJKL","mnoMNO","pqrsPQRS","tuvTUV","wxyzWXYZ"] while True: try: ans = "" sers = "" c = 0 for key in input(): if key == "0": if len(sers) > 0: n,l = int(sers[0]),len(sers) l = (l-1)%len(alpha[n]) ans += alpha[n][l] sers = "" else: ans += " " elif len(sers) == 0 or sers[-1] == key: sers += key else: n,l = int(sers[0]),len(sers) l = (l-1)%len(alpha[n]) ans += alpha[n][l] sers = key if len(sers) > 0: if sers[0] == 0: ans += " "*len(sers) else: n,l = int(sers[0]),len(sers) l = (l-1)%len(alpha[n]) ans += alpha[n][l] print(ans) except: break
[["-", 0, 1, 0, 662, 12, 634, 0, 557, 0, 6], ["+", 0, 1, 0, 662, 12, 634, 0, 557, 0, 6]]
5
270
import static java.lang.Math.*; import java.io.*; import java.util.*; class Main { static int[] makePrimes(final int lim) { BitSet isPrime = new BitSet(lim + 1); isPrime.set(0, lim + 1, true); isPrime.set(0, 2, false); final int limIndex = (int)sqrt(lim); for (int index = 2; index <= limIndex; index++) { if (isPrime.get(index)) { for (int i = index * index; i <= lim; i += index) { isPrime.set(i, false); } } } final int count = isPrime.cardinality(); int[] ans = new int[count]; int index = 0; for (int i = 0; i <= lim; i++) { if (isPrime.get(i)) { ans[index++] = i; } } return ans; } public static void main(final String[] args) { final Scanner stdin = new Scanner(System.in); final int[] primes = makePrimes(10000); while (stdin.hasNextInt()) { final int n = stdin.nextInt(); if (n <= 3) { System.out.println(0); } else { int count = 0; int index = 0; while (index < primes.length && primes[index] <= n) { if (Arrays.binarySearch(primes, n - primes[index] + 1) >= 0) { count++; } index++; } System.out.println(count); } } } }
import static java.lang.Math.*; import java.io.*; import java.util.*; class Main { static int[] makePrimes(final int lim) { BitSet isPrime = new BitSet(lim + 1); isPrime.set(0, lim + 1, true); isPrime.set(0, 2, false); final int limIndex = (int)sqrt(lim); for (int index = 2; index <= limIndex; index++) { if (isPrime.get(index)) { for (int i = index * index; i <= lim; i += index) { isPrime.set(i, false); } } } final int count = isPrime.cardinality(); int[] ans = new int[count]; int index = 0; for (int i = 0; i <= lim; i++) { if (isPrime.get(i)) { ans[index++] = i; } } return ans; } public static void main(final String[] args) { final Scanner stdin = new Scanner(System.in); final int[] primes = makePrimes(10000); while (stdin.hasNextInt()) { final int n = stdin.nextInt(); if (n <= 2) { System.out.println(0); } else { int count = 0; int index = 0; while (index < primes.length && primes[index] <= n) { if (Arrays.binarySearch(primes, n - primes[index] + 1) >= 0) { count++; } index++; } System.out.println(count); } } } }
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 12, 499]]
3
346
#include <math.h> #include <stdio.h> #define MAX 10000 int main(int argc, char const *argv[]) { int i, j, n, count = 0; int prime[MAX]; for (i = 0; i <= MAX; i++) prime[i] = 1; // i == 1 -> prime prime[0] = prime[1] = 0; // i == 0 -> !prime for (i = 2; i < sqrt(MAX); i++) { if (prime[i] == 1) { for (j = i; i * j <= MAX; j++) { prime[i * j] = 0; } } } while (scanf("%d", &n) != EOF) { for (i = 1; i <= n; i++) if (prime[i] + prime[(n + 1) - i] == 2) count++; printf("%d\n", count); } return 0; }
#include <math.h> #include <stdio.h> #define MAX 10000 int main(int argc, char const *argv[]) { int i, j, n, count = 0; int prime[MAX]; for (i = 0; i <= MAX; i++) prime[i] = 1; // i == 1 -> prime prime[0] = prime[1] = 0; // i == 0 -> !prime for (i = 2; i < sqrt(MAX); i++) { if (prime[i] == 1) { for (j = i; i * j <= MAX; j++) { prime[i * j] = 0; } } } while (scanf("%d", &n) != EOF) { count = 0; for (i = 1; i <= n; i++) if (prime[i] + prime[(n + 1) - i] == 2) count++; printf("%d\n", count); } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
0
193
#include <algorithm> #include <iostream> #include <limits.h> #include <queue> #include <string> using namespace std; typedef pair<int, int> P; const int INF = INT_MAX / 3; // const int V_MAX=10000,E_MAX=10000; // int V,E; const int N = 20000; bool primes[N]; void sieve() { fill(primes, primes + N, true); primes[0] = false; primes[1] = false; for (int i = 2; i < N; i++) if (primes[i]) for (int j = 2 * i; j < N; j += i) primes[j] = false; } int solve(int n) { int res = 0; for (int i = 1; i <= n; i++) if (primes[i] && primes[n - i + 1]) res++; return res; } int main() { int n = 0; sieve(); while (cin >> n) cout << solve(n); return 0; }
#include <algorithm> #include <iostream> #include <limits.h> #include <queue> #include <string> using namespace std; typedef pair<int, int> P; const int INF = INT_MAX / 3; // const int V_MAX=10000,E_MAX=10000; // int V,E; const int N = 20000; bool primes[N]; void sieve() { fill(primes, primes + N, true); primes[0] = false; primes[1] = false; for (int i = 2; i < N; i++) if (primes[i]) for (int j = 2 * i; j < N; j += i) primes[j] = false; } int solve(int n) { int res = 0; for (int i = 2; i < n; i++) if (primes[i] && primes[n - i + 1]) res++; return res; } int main() { int n = 0; sieve(); while (cin >> n) cout << solve(n) << 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, 15, 16, 17, 19], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 8, 9, 0, 52, 8, 1, 0, 16, 17, 151], ["+", 8, 9, 0, 52, 8, 1, 0, 16, 12, 22]]
1
201
#include <iostream> #include <string> using namespace std; int main(void) { bool m[10001]; int k; for (int i = 0; i < 10001; i++) m[i] = true; m[0] = m[1] = false; for (int i = 2; i < 10001; i++) { if (!m[i]) continue; for (int j = i * 2; j < 10001; j += i) { m[j] = false; } } while (cin >> k) { int c = 0; for (int i = 1; i <= k / 2; i++) { if (m[k - i + 1] && m[i]) c++; } c *= 2; if (m[k / 2 + 1]) c++; cout << c << endl; } }
#include <iostream> #include <string> using namespace std; int main(void) { bool m[10001]; int k; for (int i = 0; i < 10001; i++) m[i] = true; m[0] = m[1] = false; for (int i = 2; i < 10001; i++) { if (!m[i]) continue; for (int j = i * 2; j < 10001; j += i) { m[j] = false; } } while (cin >> k) { int c = 0; for (int i = 1; i <= k / 2; i++) { if (m[k - i + 1] && m[i]) c++; } c *= 2; if ((k & 1) && m[k / 2 + 1]) c++; cout << c << endl; } }
[["+", 0, 57, 15, 339, 51, 16, 31, 23, 0, 24], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 31, 22], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 17, 67], ["+", 15, 339, 51, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 57, 15, 339, 51, 16, 31, 23, 0, 25], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98]]
1
183
#include <cmath> #include <iostream> using namespace std; bool p(int n) { if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 3; i <= sqrt(n); i += 2) if (n % i == 0) return false; return true; } int main() { int n; while (cin >> n) { if (n < 4) cout << "0\n"; else { int sum = 0; for (int i = 2; i < n; i++) if (p(i) && p(n - i + 1)) sum++; cout << sum << endl; } } }
#include <cmath> #include <iostream> using namespace std; bool p(int n) { if (n == 2) return true; if (n % 2 == 0) return false; for (int i = 3; i <= sqrt(n); i += 2) if (n % i == 0) return false; return true; } int main() { int n; while (cin >> n) { if (n < 3) cout << "0\n"; else { int sum = 0; for (int i = 2; i < n; i++) if (p(i) && p(n - i + 1)) sum++; cout << sum << endl; } } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
145
import math import bisect primes=[2] top=2 nlist=[2*x-1 for x in range(2,5000)] while top<math.sqrt(10000): top=nlist[0] primes.append(top) newnlist=[] for i in nlist: if i%top!=0: newnlist.append(i) nlist=newnlist primes=primes+nlist while(1): try: n=int(input()) except: break if n%2==0: if n-1 in primes: print(2) else: print(0) else: ans=0 center=(n+1)/2 distc=[x-center for x in primes[:bisect.bisect(primes,n)]] print(distc) if 0 in distc: ans=1 il=bisect.bisect_left(distc,0)-1 ir=bisect.bisect_left(distc,0)+1 else: il=bisect.bisect_left(distc,0)-1 ir=bisect.bisect_left(distc,0) while(il>=0 and ir<len(distc)): if distc[il]+distc[ir]==0: ans=ans+2 il=il-1 ir=ir+1 elif distc[il]+distc[ir]<0: ir=ir+1 else: il=il-1 print(ans)
import math import bisect primes=[2] top=2 nlist=[2*x-1 for x in range(2,5000)] while top<math.sqrt(10000): top=nlist[0] primes.append(top) newnlist=[] for i in nlist: if i%top!=0: newnlist.append(i) nlist=newnlist primes=primes+nlist while(1): try: n=int(input()) except: break if n%2==0: if n-1 in primes: print(2) else: print(0) else: ans=0 center=(n+1)/2 distc=[x-center for x in primes[:bisect.bisect(primes,n)]] if 0 in distc: ans=1 il=bisect.bisect_left(distc,0)-1 ir=bisect.bisect_left(distc,0)+1 else: il=bisect.bisect_left(distc,0)-1 ir=bisect.bisect_left(distc,0) while(il>=0 and ir<len(distc)): if distc[il]+distc[ir]==0: ans=ans+2 il=il-1 ir=ir+1 elif distc[il]+distc[ir]<0: ir=ir+1 else: il=il-1 print(ans)
[["-", 75, 76, 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, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
291
primes = [0, 0] + [1] * 9999 for i in range(2, 101): if primes[i]: for j in range(i*i, 10001, i): primes[j] = 0 while True: try: N = int(input()) except: break print(sum(primes[i] & primes[-i] for i in range(1, N+1)))
primes = [0, 0] + [1] * 9999 for i in range(2, 101): if primes[i]: for j in range(i*i, 10001, i): primes[j] = 0 while True: try: N = int(input()) except: break print(sum(primes[i] & primes[N-i+1] for i in range(1, N+1)))
[["+", 8, 657, 12, 206, 206, 657, 31, 657, 31, 22], ["+", 3, 668, 8, 657, 12, 206, 206, 657, 17, 72], ["+", 3, 668, 8, 657, 12, 206, 206, 657, 12, 612]]
5
92
import math def ifprime(num): if num == 1: return False for i in range(2,math.floor(num ** 0.5) + 1): if num % i: continue else: return False return True while(True): try: num = input() except: break count = 0 for i in range(1,num+1): if ifprime(i) and ifprime(num-i): count += 1 print(count)
import math def ifprime(num): if num == 1: return False for i in range(2,math.floor(num ** 0.5) + 1): if num % i: continue else: return False return True while(True): try: num = int(input()) except: break count = 0 for i in range(1,num+1): if ifprime(i) and ifprime(num+1-i): count += 1 print(count)
[["+", 8, 196, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25], ["+", 12, 652, 3, 4, 0, 657, 31, 657, 17, 72], ["+", 12, 652, 3, 4, 0, 657, 31, 657, 12, 612]]
5
96
r = 10000 sqrt = int(math.sqrt(r)) p = [1 for i in range(r)] p[0] = 0 for i in range(sqrt): if p[i]: p[2*i+1::i+1] = [0 for j in range(2*i+1,r,i+1)] while True: try: n = int(input()) count = 0 for i in range(n): if p[i]*p[n-i-1] == 1: count += 1 print(count) except: break
import math r = 10000 sqrt = int(math.sqrt(r)) p = [1 for i in range(r)] p[0] = 0 for i in range(sqrt): if p[i]: p[2*i+1::i+1] = [0 for j in range(2*i+1,r,i+1)] while True: try: n = int(input()) count = 0 for i in range(n): if p[i]*p[n-i-1] == 1: count += 1 print(count) except: break
[["+", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22]]
5
131
import math r = 9999 sqrt = int(math.sqrt(r)) p = [1*r] p[0] = 0 for i in range(sqrt): if p[i]: p[2*i+1::i+1] = [0 for j in range(2*i+1,r,i+1)] prime = [] for i in range(r): if p[i]: prime.append(i) while True: try: n = int(input()) count = 0 for i in prime: if i > n-1: break if p[n-i-1] == 1: count += 1 print(count) except: break
import math r = 9999 sqrt = int(math.sqrt(r)) p = [1 for i in range(r)] p[0] = 0 for i in range(sqrt): if p[i]: p[2*i+1::i+1] = [0 for j in range(2*i+1,r,i+1)] prime = [] for i in range(r): if p[i]: prime.append(i) while True: try: n = int(input()) count = 0 for i in prime: if i > n-1: break if p[n-i-1] == 1: count += 1 print(count) except: break
[["-", 0, 1, 0, 662, 12, 634, 0, 657, 17, 48], ["+", 0, 1, 0, 662, 12, 658, 0, 659, 0, 88], ["+", 0, 1, 0, 662, 12, 658, 0, 659, 31, 22], ["+", 0, 1, 0, 662, 12, 658, 0, 659, 0, 267], ["+", 0, 662, 12, 658, 0, 659, 12, 652, 63, 22], ["+", 12, 658, 0, 659, 12, 652, 3, 4, 0, 24], ["+", 12, 658, 0, 659, 12, 652, 3, 4, 0, 25]]
5
152
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { final int n = sc.nextInt(); if (n == 0) { break; } int[][] count = new int[n][n]; int[][] data = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { data[i][j] = sc.nextInt(); } } for (int i = 0; i < n; i++) { int min = Integer.MAX_VALUE; for (int j = 0; j < n; j++) { if (min > data[i][j]) { min = data[i][j]; } } for (int j = 0; j < n; j++) { if (min == data[i][j]) { count[i][j]++; } } } for (int i = 0; i < n; i++) { int max = Integer.MIN_VALUE; for (int j = 0; j < n; j++) { if (max < data[j][i]) { max = data[j][i]; } } for (int j = 0; j < n; j++) { if (max == data[j][i]) { count[j][i]++; } } } int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (count[i][j] >= 2 && max < data[i][j]) { max = data[i][j]; } } } if (max == Integer.MAX_VALUE) { System.out.println(0); } else { System.out.println(max); } } } }
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (true) { final int n = sc.nextInt(); if (n == 0) { break; } int[][] count = new int[n][n]; int[][] data = new int[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { data[i][j] = sc.nextInt(); } } for (int i = 0; i < n; i++) { int min = Integer.MAX_VALUE; for (int j = 0; j < n; j++) { if (min > data[i][j]) { min = data[i][j]; } } for (int j = 0; j < n; j++) { if (min == data[i][j]) { count[i][j]++; } } } for (int i = 0; i < n; i++) { int max = Integer.MIN_VALUE; for (int j = 0; j < n; j++) { if (max < data[j][i]) { max = data[j][i]; } } for (int j = 0; j < n; j++) { if (max == data[j][i]) { count[j][i]++; } } } // System.out.println(Arrays.deepToString(count)); int max = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (count[i][j] >= 2 && max < data[i][j]) { max = data[i][j]; } } } if (max == Integer.MIN_VALUE) { System.out.println(0); } else { System.out.println(max); } } } }
[["-", 0, 57, 15, 15, 0, 16, 12, 509, 119, 22], ["+", 0, 57, 15, 15, 0, 16, 12, 509, 119, 22]]
3
454
// Aizu Vol-10 1005: Advanced Algorithm Class // 2017.8.17 bal4u@uu #include <stdio.h> #define N 100 int a[N][N][3], n; int main() { int r, c, h, t, min, max; while (scanf("%d", &n) == 1 && n) { for (r = 0; r < n; r++) for (c = 0; c < n; c++) scanf("%d", &a[r][c][0]); for (r = 0; r < n; r++) { min = a[r][0][0]; for (c = 1; c < n; c++) { if (a[r][c][0] < min) min = a[r][c][0]; } for (c = 0; c < n; c++) a[r][c][1] = (a[r][c][0] == min); } for (c = 0; c < n; c++) { max = a[0][c][0]; for (r = 1; r < n; r++) { if (a[r][c][0] > max) max = a[r][c][0]; } for (r = 0; r < n; r++) a[r][c][2] = (a[r][c][0] == max); } for (t = 0, r = 0; r < n; r++) for (c = 0; c < n; c++) { if (a[r][c][1] && a[r][c][2]) h = a[r][c][0], t++; } if (t > 1) h = 0; printf("%d\n", h); } return 0; }
// Aizu Vol-10 1005: Advanced Algorithm Class // 2017.8.17 bal4u@uu #include <stdio.h> #define N 100 int a[N][N][3], n; int main() { int r, c, h, t, min, max; while (scanf("%d", &n) == 1 && n) { for (r = 0; r < n; r++) for (c = 0; c < n; c++) scanf("%d", &a[r][c][0]); for (r = 0; r < n; r++) { min = a[r][0][0]; for (c = 1; c < n; c++) { if (a[r][c][0] < min) min = a[r][c][0]; } for (c = 0; c < n; c++) a[r][c][1] = (a[r][c][0] == min); } for (c = 0; c < n; c++) { max = a[0][c][0]; for (r = 1; r < n; r++) { if (a[r][c][0] > max) max = a[r][c][0]; } for (r = 0; r < n; r++) a[r][c][2] = (a[r][c][0] == max); } for (t = 0, r = 0; r < n; r++) for (c = 0; c < n; c++) { if (a[r][c][1] && a[r][c][2]) h = a[r][c][0], t++; } if (t == 0) h = 0; // t > 1 ???? printf("%d\n", h); } return 0; }
[["-", 8, 9, 0, 57, 15, 23, 0, 16, 17, 47], ["-", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 23, 0, 16, 12, 13]]
0
418
#include <algorithm> #include <iostream> using namespace std; const int INF = 1 << 20; int main() { int n, i, j, a, b; for (; cin >> n, n;) { int m[100][100], rec[100], t[100][100], mv, ind; for (i = 0; i < n; i++) { rec[i] = 0; for (j = 0; j < n; j++) { m[i][j] = t[i][j] = 0; } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> m[i][j]; } } for (i = 0; i < n; i++) { mv = INF, ind = 0; for (j = 0; j < n; j++) { if (m[i][j] < mv) ind = 0; if (m[i][j] <= mv) { mv = m[i][j]; rec[ind++] = j; } } for (j = 0; j < ind; j++) { t[i][rec[j]]++; } } for (i = 0; i < n; i++) { mv = -INF, ind = 0; for (j = 0; j < n; j++) { if (m[j][i] > mv) ind = 0; if (m[j][i] >= mv) { mv = m[j][i]; rec[ind++] = j; } } for (j = 0; j < ind; j++) { t[rec[j]][i]++; } } bool flg = false; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (t[i][j] / 2) { cout << m[i][j] << endl; flg = true; } } } if (!flg) cout << 0 << endl; } return 0; }
#include <algorithm> #include <iostream> using namespace std; const int INF = 1 << 20; int main() { int n, i, j, a, b; for (; cin >> n, n;) { int m[100][100], rec[100], t[100][100], mv, ind; for (i = 0; i < n; i++) { rec[i] = 0; for (j = 0; j < n; j++) { m[i][j] = t[i][j] = 0; } } for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> m[i][j]; } } for (i = 0; i < n; i++) { mv = INF, ind = 0; for (j = 0; j < n; j++) { if (m[i][j] < mv) ind = 0; if (m[i][j] <= mv) { mv = m[i][j]; rec[ind++] = j; } } for (j = 0; j < ind; j++) { t[i][rec[j]]++; } } for (i = 0; i < n; i++) { mv = -INF, ind = 0; for (j = 0; j < n; j++) { if (m[j][i] > mv) ind = 0; if (m[j][i] >= mv) { mv = m[j][i]; rec[ind++] = j; } } for (j = 0; j < ind; j++) { t[rec[j]][i]++; } } bool flg = false; for (i = 0; i < n && !flg; i++) { for (j = 0; j < n && !flg; j++) { if (t[i][j] / 2) { cout << m[i][j] << endl; flg = true; } } } if (!flg) cout << 0 << endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 7, 15, 16, 17, 98], ["+", 8, 9, 0, 7, 15, 16, 12, 91, 17, 111], ["+", 8, 9, 0, 7, 15, 16, 12, 91, 28, 22]]
1
472
#include <iostream> #define NMAX 100 using namespace std; int main() { int n; int input; int class_room[NMAX][NMAX]; int class_room_hand[NMAX][NMAX]; // 1 right 2 left 3 both int right[NMAX] = {0}; int left[NMAX] = {0}; int ans = 0; int ans_n = 0; while (cin >> n) { if (n == 0) { break; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> input; class_room[i][j] = input; } } for (int i = 0; i < n; i++) { right[i] = class_room[i][0]; for (int j = 0; j < n; j++) { if (right[i] > class_room[i][j]) { right[i] = class_room[i][j]; } if (left[i] < class_room[j][i]) { left[i] = class_room[j][i]; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (right[i] == class_room[i][j]) { class_room_hand[i][j] |= 1; } if (left[i] == class_room[j][i]) { class_room_hand[j][i] |= 2; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (class_room_hand[i][j] == 3) { ans_n++; ans = class_room[i][j]; } } } if (ans_n == 1) { cout << ans << endl; } else { cout << 0 << endl; } ans_n = 0; ans = 0; fill((int *)class_room, (int *)(class_room + NMAX), 0); fill((int *)class_room_hand, (int *)(class_room_hand + NMAX), 0); fill(right, right + (sizeof(right) / sizeof *(right)), 0); fill(left, left + (sizeof(left) / sizeof *(left)), 0); } return 0; }
#include <iostream> #define NMAX 100 using namespace std; int main() { int n; int input; int class_room[NMAX][NMAX]; int class_room_hand[NMAX][NMAX]; // 1 right 2 left 3 both int right[NMAX] = {0}; int left[NMAX] = {0}; int ans = 0; int ans_n = 0; while (cin >> n) { if (n == 0) { break; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> input; class_room[i][j] = input; } } for (int i = 0; i < n; i++) { right[i] = class_room[i][0]; for (int j = 0; j < n; j++) { if (right[i] > class_room[i][j]) { right[i] = class_room[i][j]; } if (left[i] < class_room[j][i]) { left[i] = class_room[j][i]; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (right[i] == class_room[i][j]) { class_room_hand[i][j] |= 1; } if (left[i] == class_room[j][i]) { class_room_hand[j][i] |= 2; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (class_room_hand[i][j] == 3) { ans_n++; ans = class_room[i][j]; } } } if (ans_n >= 1) { cout << ans << endl; } else { cout << 0 << endl; } ans_n = 0; ans = 0; fill((int *)class_room, (int *)(class_room + NMAX), 0); fill((int *)class_room_hand, (int *)(class_room_hand + NMAX), 0); fill(right, right + (sizeof(right) / sizeof *(right)), 0); fill(left, left + (sizeof(left) / sizeof *(left)), 0); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
504
#include <algorithm> #include <stdio.h> using namespace std; int b[110][110]; int main() { int a; while (scanf("%d", &a), a) { for (int i = 0; i < a; i++) for (int j = 0; j < a; j++) scanf("%d", &b[i][j]); bool yet = true; for (int i = 0; i < a; i++) { for (int j = 0; j < a; j++) { bool ok = true; for (int k = 0; k < a; k++) if (b[i][j] > b[i][k] || b[i][j] < b[k][j]) ok = false; if (ok) { printf("%d\n", b[i][j]); yet = false; } } } if (yet) printf("0\n"); } }
#include <algorithm> #include <stdio.h> using namespace std; int b[110][110]; int main() { int a; while (scanf("%d", &a), a) { for (int i = 0; i < a; i++) for (int j = 0; j < a; j++) scanf("%d", &b[i][j]); bool yet = true; for (int i = 0; i < a; i++) { for (int j = 0; j < a; j++) { bool ok = true; for (int k = 0; k < a; k++) if (b[i][j] > b[i][k] || b[i][j] < b[k][j]) ok = false; if (ok && yet) { printf("%d\n", b[i][j]); yet = false; } } } if (yet) printf("0\n"); } }
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
218
#include <algorithm> #include <iostream> using namespace std; int main() { int n, m, row[100], column[100]; while (cin >> n) { if (n == 0) break; fill(row, row + n, 0); fill(column, column + n, 10000); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> m; row[j] = max(row[j], m); column[i] = min(column[i], m); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (row[i] == column[j]) { cout << row[i] << endl; i = n; break; } if (i == n - 1) cout << 0 << endl; } } } return 0; }
#include <algorithm> #include <iostream> using namespace std; int main() { int n, m, row[100], column[100]; while (cin >> n) { if (n == 0) break; fill(row, row + n, 0); fill(column, column + n, 10000); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> m; row[j] = max(row[j], m); column[i] = min(column[i], m); } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (row[i] == column[j]) { cout << row[i] << endl; i = n; break; } } if (i == n - 1) cout << 0 << endl; } } return 0; }
[["+", 0, 7, 8, 9, 0, 7, 8, 9, 0, 46], ["-", 0, 7, 8, 9, 0, 7, 8, 9, 0, 46]]
1
211
#include <stdio.h> int n, a[99][99]; int main() { while (scanf("%d", &n), n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); } bool flag = false; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!flag) { bool ok = true; for (int k = 0; k < n; k++) { if (j != k && a[i][j] >= a[i][k]) ok = false; if (i != k && a[i][j] <= a[k][j]) ok = false; } if (ok) printf("%d\n", a[i][j]), flag = true; } } } if (!flag) printf("0\n"); } }
#include <stdio.h> int n, a[99][99]; int main() { while (scanf("%d", &n), n) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); } bool flag = false; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (!flag) { bool ok = true; for (int k = 0; k < n; k++) { if (j != k && a[i][j] > a[i][k]) ok = false; if (i != k && a[i][j] < a[k][j]) ok = false; } if (ok) printf("%d\n", a[i][j]), flag = true; } } } if (!flag) printf("0\n"); } }
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18]]
1
235
#include <bits/stdc++.h> #define N 100 using namespace std; int n, a[N][N], ans; bool checkx(int y, int x, int p) { for (int i = 0; i < n; i++) if (x != i && p > a[y][i]) return false; return true; } bool checky(int y, int x, int p) { for (int i = 0; i < n; i++) if (y != i && p < a[i][x]) return false; return true; } int main() { while (1) { cin >> n; if (!n) break; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (checkx(i, j, a[i][j]) && checky(i, j, a[i][j])) ans = a[i][j]; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define N 100 using namespace std; int n, a[N][N], ans; bool checkx(int y, int x, int p) { for (int i = 0; i < n; i++) if (x != i && p > a[y][i]) return false; return true; } bool checky(int y, int x, int p) { for (int i = 0; i < n; i++) if (y != i && p < a[i][x]) return false; return true; } int main() { while (1) { cin >> n; if (!n) break; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> a[i][j]; ans = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (checkx(i, j, a[i][j]) && checky(i, j, a[i][j])) ans = a[i][j]; cout << ans << endl; } return 0; }
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
262
#include "bits/stdc++.h" using namespace std; //#define int long long #define DEBUG 0 #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(a) (a).begin(), (a).end() #define dump(o) \ if (DEBUG) { \ cerr << #o << " " << o << endl; \ } #define dumpc(o) \ if (DEBUG) { \ cerr << #o; \ for (auto &e : (o)) \ cerr << " " << e; \ cerr << endl; \ } using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; static const int MOD = 1e9 + 7; signed main() { int a[110][110] = {}; int b[110][110] = {}; for (int n; cin >> n && n;) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); rep(i, 0, n) rep(j, 0, n) cin >> a[i][j]; rep(i, 0, n) { int m = INF; rep(j, 0, n) if (m > a[i][j]) m = a[i][j]; rep(j, 0, n) if (m == a[i][j]) b[i][j]++; } rep(j, 0, n) { int M = -INF; rep(i, 0, n) if (M < a[i][j]) M = a[i][j]; rep(i, 0, n) if (M == a[i][j]) b[i][j]++; } rep(i, 0, n) dumpc(b[i]); bool flag = true; rep(i, 0, n) rep(j, 0, n) if (b[i][j] == 2) { cout << a[i][j] << endl; flag = false; } if (flag) cout << 0 << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; //#define int long long #define DEBUG 0 #define rep(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--) #define all(a) (a).begin(), (a).end() #define dump(o) \ if (DEBUG) { \ cerr << #o << " " << o << endl; \ } #define dumpc(o) \ if (DEBUG) { \ cerr << #o; \ for (auto &e : (o)) \ cerr << " " << e; \ cerr << endl; \ } using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; static const int MOD = 1e9 + 7; signed main() { int a[110][110] = {}; int b[110][110] = {}; for (int n; cin >> n && n;) { memset(a, 0, sizeof(a)); memset(b, 0, sizeof(b)); rep(i, 0, n) rep(j, 0, n) cin >> a[i][j]; rep(i, 0, n) { int m = INF; rep(j, 0, n) if (m > a[i][j]) m = a[i][j]; rep(j, 0, n) if (m == a[i][j]) b[i][j]++; } rep(j, 0, n) { int M = -INF; rep(i, 0, n) if (M < a[i][j]) M = a[i][j]; rep(i, 0, n) if (M == a[i][j]) b[i][j]++; } rep(i, 0, n) dumpc(b[i]); bool flag = true; rep(i, 0, n) rep(j, 0, n) if (b[i][j] == 2) { cout << a[i][j] << endl; flag = false; i = n; break; } if (flag) cout << 0 << endl; } return 0; }
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
1
433
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int h[100][100]; bool lef[100][100], rig[100][100]; int main() { int n; while (scanf("%d", &n), n) { memset(lef, 0, sizeof(lef)); memset(rig, 0, sizeof(rig)); rep(i, n) rep(j, n) scanf("%d", &h[i][j]); rep(i, n) { int Min = *min_element(h[i], h[i] + n); rep(j, n) { if (h[i][j] == Min) lef[i][j] = true; } } rep(i, n) { int Max = 0; rep(j, n) { if (Max < h[j][i]) Max = h[j][i]; } rep(j, n) { if (h[j][i] == Max) rig[j][i] = true; } } rep(i, n) rep(j, n) { if (lef[i][j] && rig[i][j]) { printf("%d\n", h[i][j]); goto g; } } g:; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int h[100][100]; bool lef[100][100], rig[100][100]; int main() { int n; while (scanf("%d", &n), n) { memset(lef, 0, sizeof(lef)); memset(rig, 0, sizeof(rig)); rep(i, n) rep(j, n) scanf("%d", &h[i][j]); rep(i, n) { int Min = *min_element(h[i], h[i] + n); rep(j, n) { if (h[i][j] == Min) lef[i][j] = true; } } rep(i, n) { int Max = 0; rep(j, n) { if (Max < h[j][i]) Max = h[j][i]; } rep(j, n) { if (h[j][i] == Max) rig[j][i] = true; } } rep(i, n) rep(j, n) { if (lef[i][j] && rig[i][j]) { printf("%d\n", h[i][j]); goto g; } } puts("0"); g:; } }
[["+", 0, 52, 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, 6], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
306
#include <iostream> #include <vector> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; int main(void) { int n; while (cin >> n && n) { VVI students(n, VI(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> students[i][j]; VVI tallests(n, VI(n, 0)); VVI shortests(n, VI(n, 0)); // get shortest for (int i = 0; i < n; i++) { int shortest; int shortest_col; for (int j = 0; j < n; j++) { if (j == 0 || shortest > students[i][j]) { shortest = students[i][j]; shortest_col = j; } } for (int j = 0; j < n; j++) { if (shortest == students[i][j]) shortests[i][shortest_col] = 1; } } // get tallest for (int i = 0; i < n; i++) { int tallest; int tallest_row; for (int j = 0; j < n; j++) { if (j == 0 || tallest < students[j][i]) { tallest = students[j][i]; tallest_row = j; } } int cnt = 0; for (int j = 0; j < n; j++) { if (tallest == students[j][i]) tallests[tallest_row][i] = 1; } } int answer = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (tallests[i][j] && shortests[i][j]) answer = students[i][j]; } } cout << answer << endl; } return 0; }
#include <iostream> #include <vector> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; int main(void) { int n; while (cin >> n && n) { VVI students(n, VI(n)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> students[i][j]; VVI tallests(n, VI(n, 0)); VVI shortests(n, VI(n, 0)); // get shortest for (int i = 0; i < n; i++) { int shortest; int shortest_col; for (int j = 0; j < n; j++) { if (j == 0 || shortest > students[i][j]) { shortest = students[i][j]; shortest_col = j; } } for (int j = 0; j < n; j++) { if (shortest == students[i][j]) shortests[i][j] = 1; } } // get tallest for (int i = 0; i < n; i++) { int tallest; int tallest_row; for (int j = 0; j < n; j++) { if (j == 0 || tallest < students[j][i]) { tallest = students[j][i]; tallest_row = j; } } int cnt = 0; for (int j = 0; j < n; j++) { if (tallest == students[j][i]) tallests[j][i] = 1; } } int answer = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (tallests[i][j] && shortests[i][j]) answer = students[i][j]; } } cout << answer << endl; } return 0; }
[["-", 64, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 64, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 0, 11, 31, 69, 28, 69, 341, 342, 0, 22], ["+", 0, 11, 31, 69, 28, 69, 341, 342, 0, 22]]
1
414
#include <iostream> using namespace std; int main() { int n; int imap[110][110]; int mmap[110][2]; // 0->row 1->column while (cin >> n && n) { for (int i = 0; i < n; i++) { mmap[i][1] = 1 << 30; mmap[i][0] = 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> imap[i][j]; mmap[j][0] = max(mmap[j][0], imap[i][j]); } for (int j = 0; j < n; j++) mmap[i][1] = min(mmap[i][1], imap[i][j]); } bool found = false; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (mmap[i][0] == mmap[j][1]) { cout << mmap[i][0] << endl; found = true; break; } } } if (!found) cout << "0" << endl; } return 0; }
#include <iostream> using namespace std; int main() { int n; int imap[110][110]; int mmap[110][2]; // 0->row 1->column while (cin >> n && n) { for (int i = 0; i < n; i++) { mmap[i][1] = 1 << 30; mmap[i][0] = 0; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> imap[i][j]; mmap[j][0] = max(mmap[j][0], imap[i][j]); } for (int j = 0; j < n; j++) mmap[i][1] = min(mmap[i][1], imap[i][j]); } bool found = false; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (mmap[i][0] == mmap[j][1]) { cout << mmap[i][0] << endl; found = true; break; } } if (found) break; } if (!found) cout << "0" << endl; } return 0; }
[["+", 8, 9, 0, 7, 8, 9, 0, 57, 0, 121], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 51, 22], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 7, 8, 9, 0, 57, 64, 93, 0, 94], ["+", 0, 7, 8, 9, 0, 57, 64, 93, 0, 35]]
1
283
while gets n = $_.to_i break if n == 0 m = Array.new(n){ Array.new(n) } n.times { |i| m[i] = gets.split.map(&:to_i) } a = Array.new n.times { |i| a << m[i].min } mt = m.transpose b = Array.new n.times { |i| b << mt[i].max } puts a & b == nil ? 0 : a & b end
while gets n = $_.to_i break if n == 0 m = Array.new(n){ Array.new(n) } n.times { |i| m[i] = gets.split.map(&:to_i) } a = Array.new n.times { |i| a << m[i].min } mt = m.transpose b = Array.new n.times { |i| b << mt[i].max } puts (a & b).empty? ? 0 : a & b end
[["+", 3, 4, 0, 754, 15, 652, 486, 739, 0, 24], ["-", 0, 652, 3, 4, 0, 754, 15, 738, 17, 60], ["-", 3, 4, 0, 754, 15, 738, 12, 477, 0, 477], ["+", 3, 4, 0, 754, 15, 652, 486, 739, 0, 25], ["+", 0, 652, 3, 4, 0, 754, 15, 652, 17, 131], ["+", 0, 652, 3, 4, 0, 754, 15, 652, 735, 22]]
4
110
function bomb(y, x, f) { yx[y][x] = (" " + cnt).slice(-3); cnt++; if (y == n - 1 && x == n - 1) return; else if (y == n - 1 && f == -1) bomb(y, x + 1, 1); else if (y == n - 1 && f == 1) bomb(y - 1, x + 1, 1); else if (x == n - 1 && f == 1) bomb(y + 1, x, -1); else if (x == n - 1 && f == -1) bomb(y + 1, x - 1, -1); else if (y == 0 && f == 1) bomb(y, x + 1, -1); else if (y == 0 && f == -1) bomb(y + 1, x - 1, -1); else if (x == 0 && f == -1) bomb(y + 1, x, 1); else if (x == 0 && f == 1) bomb(y - 1, x + 1, 1); else if (f == 1) bomb(y - 1, x + 1, 1); else if (f == -1) bomb(y + 1, x - 1, -1); } var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var Arr = (input.trim()).split("\n"); var I = 1; while (true) { var n = Arr.shift() - 0; if (n == 0) break; var yx = []; for (var i = 0; i < n; i++) { yx[i] = []; for (var j = 0; j < n; j++) { yx[i][j] = 0; } } bomb(0, 0, 1); console.log("Case " + I + ":"); I++; console.log(yx.join("\n").replace(/\,/g, "")); }
function bomb(y, x, f) { yx[y][x] = (" " + cnt).slice(-3); cnt++; if (y == n - 1 && x == n - 1) return; else if (y == n - 1 && f == -1) bomb(y, x + 1, 1); else if (y == n - 1 && f == 1) bomb(y - 1, x + 1, 1); else if (x == n - 1 && f == 1) bomb(y + 1, x, -1); else if (x == n - 1 && f == -1) bomb(y + 1, x - 1, -1); else if (y == 0 && f == 1) bomb(y, x + 1, -1); else if (y == 0 && f == -1) bomb(y + 1, x - 1, -1); else if (x == 0 && f == -1) bomb(y + 1, x, 1); else if (x == 0 && f == 1) bomb(y - 1, x + 1, 1); else if (f == 1) bomb(y - 1, x + 1, 1); else if (f == -1) bomb(y + 1, x - 1, -1); } var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var Arr = (input.trim()).split("\n"); var I = 1; while (true) { var n = Arr.shift() - 0; if (n == 0) break; var yx = []; for (var i = 0; i < n; i++) { yx[i] = []; for (var j = 0; j < n; j++) { yx[i][j] = 0; } } var cnt = 1; bomb(0, 0, 1); console.log("Case " + I + ":"); I++; console.log(yx.join("\n").replace(/\,/g, "")); }
[["+", 0, 493, 0, 52, 8, 556, 0, 198, 0, 217], ["+", 0, 52, 8, 556, 0, 198, 0, 200, 141, 22], ["+", 0, 52, 8, 556, 0, 198, 0, 200, 0, 32], ["+", 0, 52, 8, 556, 0, 198, 0, 200, 51, 555], ["+", 0, 493, 0, 52, 8, 556, 0, 198, 0, 35]]
2
471