#include <cstdio> #include <map> #include <vector> #include <algorithm> using namespace std; typedef long long int lld; struct ssum { lld cnt,dist,eat; }; typedef struct ssum sum; typedef map<lld,sum> mlld; typedef vector<lld> vlld; int main() { lld N,n,s,T,prv; mlld S; mlld::iterator Si,prvSi; vlld O; vlld::iterator Oi; scanf("%lld",&N); for (n = 0; n < N; n++) { scanf("%lld",&s); if (S.find(s) != S.end()) S[s].cnt++; else S[s].cnt = 1; O.push_back(s); } for (Si = S.begin(); Si != S.end(); ++Si) { if (Si == S.begin()) { Si->second.dist = 0; Si->second.eat = 0; prvSi = Si; } else { Si->second.dist = prvSi->first * prvSi->second.cnt + prvSi->second.dist; if (prvSi->first+prvSi->second.dist > Si->first) prvSi->second.eat = 1; else prvSi->second.eat = 0; ++prvSi; } } prvSi->second.eat = 1; /* for (Si = S.begin(); Si != S.end(); ++Si) { printf("%lld %lld %lld %lld\n",Si->first,Si->second.cnt,Si->second.dist,Si->second.eat); } printf("\n"); */ for (Oi = O.begin(); Oi != O.end(); ++Oi) { printf("%c",(S[*Oi].eat == 1)?'T':'N'); } printf("\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 | #include <cstdio> #include <map> #include <vector> #include <algorithm> using namespace std; typedef long long int lld; struct ssum { lld cnt,dist,eat; }; typedef struct ssum sum; typedef map<lld,sum> mlld; typedef vector<lld> vlld; int main() { lld N,n,s,T,prv; mlld S; mlld::iterator Si,prvSi; vlld O; vlld::iterator Oi; scanf("%lld",&N); for (n = 0; n < N; n++) { scanf("%lld",&s); if (S.find(s) != S.end()) S[s].cnt++; else S[s].cnt = 1; O.push_back(s); } for (Si = S.begin(); Si != S.end(); ++Si) { if (Si == S.begin()) { Si->second.dist = 0; Si->second.eat = 0; prvSi = Si; } else { Si->second.dist = prvSi->first * prvSi->second.cnt + prvSi->second.dist; if (prvSi->first+prvSi->second.dist > Si->first) prvSi->second.eat = 1; else prvSi->second.eat = 0; ++prvSi; } } prvSi->second.eat = 1; /* for (Si = S.begin(); Si != S.end(); ++Si) { printf("%lld %lld %lld %lld\n",Si->first,Si->second.cnt,Si->second.dist,Si->second.eat); } printf("\n"); */ for (Oi = O.begin(); Oi != O.end(); ++Oi) { printf("%c",(S[*Oi].eat == 1)?'T':'N'); } printf("\n"); return 0; } |