Niestety, nie byliśmy w stanie w pełni poprawnie wyświetlić tego pliku, ponieważ nie jest zakodowany w UTF-8.
Możesz pobrać ten plik i spróbować otworzyć go samodzielnie.
#include <stdio.h> #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; typedef vector<int> VI; typedef long long LL; typedef pair<int,int> para; #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define PB push_back #define ST first #define ND second #define MP make_pair #define INF 1000001 struct kubek { LL t, v, h, sh, sv; //temperatura, pojemnosc, cieplo, suma ciepla, suma pojemnosci }; inline bool compare(const kubek &a, const kubek &b) { return a.t < b.t; } int main() { int t; scanf("%d", &t); REP(i,t) { int n, a, b, v0, m0=INF, m1=INF, M0=0, M1=0; LL l, l0, l1, s=0, s1=0, s2=0, s3=0, s4=0; kubek c; vector< kubek > x, y; scanf("%d", &n); x.reserve(n); y.reserve(n); REP(j,n) { scanf("%d%d%d", &v0, &a, &b); c.v=l=v0; c.t=a; c.h=l0=l*a; x.PB(c); c.t=b; c.h=l1=l*b; y.PB(c); if (a<m0) m0=a; if (b<m1) m1=b; if (a>M0) M0=a; if (b>M1) M1=b; s+=l0-l1; } /* if ( m0>m1 || M0<M1 || s!=0) { printf("%s","NIE\n"); continue; } */ sort(ALL(x), compare); sort(ALL(y), compare); REP(j,n) { s1+=x[j].v; s2+=x[j].h; x[j].sv=s1; x[j].sh=s2; s3+=y[j].v; s4+=y[j].h; y[j].sv=s3; y[j].sh=s4; } //if (x[n-1].sh != y[n-1].sh) {printf("%s","NIE\n"); continue;} int k=0; LL sv, h, h1, d, d1; bool ok=true; REP(j,n) { sv=y[j].sv; h=y[j].sh; while (x[k].sv < sv) k++; //wyjd� gdy x[k].sv >=sv d=x[k].sv-sv; d1= x[k].sh - d*x[k].t - y[j].sh; //cout<<d1<<endl; if (d1>0) {ok=false; break;} } if (ok) printf("%s","TAK\n"); else printf("%s","NIE\n"); } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | #include <stdio.h> #include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <stack> using namespace std; typedef vector<int> VI; typedef long long LL; typedef pair<int,int> para; #define FOR(x, b, e) for(int x = b; x <= (e); ++x) #define FORD(x, b, e) for(int x = b; x >= (e); --x) #define REP(x, n) for(int x = 0; x < (n); ++x) #define VAR(v, n) __typeof(n) v = (n) #define ALL(c) (c).begin(), (c).end() #define SIZE(x) ((int)(x).size()) #define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define PB push_back #define ST first #define ND second #define MP make_pair #define INF 1000001 struct kubek { LL t, v, h, sh, sv; //temperatura, pojemnosc, cieplo, suma ciepla, suma pojemnosci }; inline bool compare(const kubek &a, const kubek &b) { return a.t < b.t; } int main() { int t; scanf("%d", &t); REP(i,t) { int n, a, b, v0, m0=INF, m1=INF, M0=0, M1=0; LL l, l0, l1, s=0, s1=0, s2=0, s3=0, s4=0; kubek c; vector< kubek > x, y; scanf("%d", &n); x.reserve(n); y.reserve(n); REP(j,n) { scanf("%d%d%d", &v0, &a, &b); c.v=l=v0; c.t=a; c.h=l0=l*a; x.PB(c); c.t=b; c.h=l1=l*b; y.PB(c); if (a<m0) m0=a; if (b<m1) m1=b; if (a>M0) M0=a; if (b>M1) M1=b; s+=l0-l1; } /* if ( m0>m1 || M0<M1 || s!=0) { printf("%s","NIE\n"); continue; } */ sort(ALL(x), compare); sort(ALL(y), compare); REP(j,n) { s1+=x[j].v; s2+=x[j].h; x[j].sv=s1; x[j].sh=s2; s3+=y[j].v; s4+=y[j].h; y[j].sv=s3; y[j].sh=s4; } //if (x[n-1].sh != y[n-1].sh) {printf("%s","NIE\n"); continue;} int k=0; LL sv, h, h1, d, d1; bool ok=true; REP(j,n) { sv=y[j].sv; h=y[j].sh; while (x[k].sv < sv) k++; //wyjd� gdy x[k].sv >=sv d=x[k].sv-sv; d1= x[k].sh - d*x[k].t - y[j].sh; //cout<<d1<<endl; if (d1>0) {ok=false; break;} } if (ok) printf("%s","TAK\n"); else printf("%s","NIE\n"); } return 0; } |