File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < algorithm>
3+ #include < string>
4+ #include < vector>
5+ using namespace std ;
6+
7+ string str;
8+
9+ void run () {
10+ int mm[26 ] = {0 };
11+ getline (cin, str);
12+ for (int i = 0 ; i < str.length (); ++i) {
13+ char ch = tolower (str[i]);
14+ if (ch < ' a' || ch > ' z' ) continue ;
15+ ++mm[ch - ' a' ];
16+ }
17+ vector<int > ct;
18+ for (int i = 0 ; i < 26 ; ++i) {
19+ if (mm[i] != 0 ) ct.push_back (mm[i]);
20+ }
21+ sort (ct.begin (), ct.end ());
22+ int ret = 0 , mu = 26 ;
23+ for (int i = ct.size () - 1 ; i >= 0 ; --i, --mu) {
24+ ret += mu * ct[i];
25+ }
26+ cout << ret << endl;
27+ }
28+
29+ int main () {
30+ int m;
31+ cin >> m;
32+ getline (cin, str);
33+ for (int i = 1 ; i <= m; ++i) {
34+ cout << " Case #" << i << " : " ;
35+ run ();
36+ }
37+ return 0 ;
38+ }
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < cstring>
3+ #include < string>
4+ using namespace std ;
5+
6+ #define REP (i,n ) for (int i=0 ;i<(n);++i)
7+ #define FOR (i,a,b ) for (int i=(a);i<=(b);++i)
8+
9+ string str;
10+ int len;
11+ int mm[105 ][105 ];
12+
13+ int dp (int st, int ed) {
14+ int & ret = mm[st][ed];
15+ if (ret != -1 ) return ret;
16+
17+ if (st > ed) return ret = 1 ;
18+
19+ FOR (i,st,ed) {
20+ if (str[i] == ' (' ) {
21+ if (i - 1 >= st && str[i - 1 ] == ' :' ) {
22+ if (dp (i + 1 , ed) == 1 ) return ret = 1 ;
23+ }
24+ FOR (j,i+1 ,ed) {
25+ if (str[j] == ' )' ) {
26+ if (dp (i + 1 , j - 1 ) == 1 && dp (j + 1 , ed) == 1 ) return ret = 1 ;
27+ }
28+ }
29+ return ret = 0 ;
30+ } else if (str[i] == ' )' ) {
31+ if (i - 1 >= st && str[i - 1 ] == ' :' ) {
32+ return ret = dp (i + 1 , ed);
33+ }
34+ return ret = 0 ;
35+ }
36+ }
37+
38+ return ret = 1 ;
39+ }
40+
41+ bool isvalid (char ch) {
42+ if ((ch >= ' a' && ch <= ' z' ) || ch == ' ' || ch == ' :' || ch == ' (' || ch == ' )' ) return true ;
43+ return false ;
44+ }
45+
46+ bool run () {
47+ REP (i,len) {
48+ if (!isvalid (str[i])) return false ;
49+ }
50+ memset (mm, -1 , sizeof (mm));
51+ int ret = dp (0 , len - 1 );
52+ return ret == 1 ;
53+ }
54+
55+ int main () {
56+ int m;
57+ cin >> m;
58+ getline (cin, str);
59+ FOR (i,1 ,m) {
60+ cout << " Case #" << i << " : " ;
61+ getline (cin, str);
62+ len = str.length ();
63+ if (str.empty ()) {
64+ cout << " YES" << endl;
65+ continue ;
66+ }
67+ if (run ()) cout << " YES" << endl;
68+ else cout << " NO" << endl;
69+ }
70+ return 0 ;
71+ }
Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < algorithm>
3+ #include < vector>
4+ using namespace std ;
5+
6+ #define REP (i,n ) for (int i=0 ;i<(n);++i)
7+ #define FOR (i,a,b ) for (int i=(a);i<=(b);++i)
8+ #define INF 1000000000
9+ typedef long long LL ;
10+
11+ void run () {
12+ int n, k, a, b, c, r;
13+ cin >> n >> k >> a >> b >> c >> r;
14+ vector<int > mm (k);
15+ mm[0 ] = a;
16+ FOR (i,1 ,k-1 ) {
17+ LL t = b;
18+ t *= mm[i - 1 ];
19+ t += c;
20+ mm[i] = t % r;
21+ }
22+ vector<int > t (k + 1 ), v (k + 5 , 0 );
23+ REP (i,k) {
24+ if (mm[i] < k) v[mm[i]]++;
25+ }
26+ int pt = 0 ;
27+ int last = INF ;
28+ REP (i,k) {
29+ while (v[pt] >= 1 ) ++pt;
30+ int idx = -1 ;
31+ if (last < pt && v[last] == 0 ) idx = last;
32+ else {
33+ idx = pt;
34+ ++pt;
35+ }
36+ t[i] = idx;
37+ v[idx]++;
38+ if (mm[i] < k) {
39+ v[mm[i]]--;
40+ }
41+ last = mm[i];
42+ }
43+ while (v[pt] >= 1 ) ++pt;
44+ t[k] = min (last, pt);
45+ n %= (k + 1 );
46+ cout << t[n] << endl;
47+ }
48+
49+ int main () {
50+ int m;
51+ cin >> m;
52+ FOR (i,1 ,m) {
53+ cout << " Case #" << i << " : " ;
54+ run ();
55+ }
56+ return 0 ;
57+ }
Original file line number Diff line number Diff line change 1+ https://www.facebook.com/hackercup/problems.php?round=185564241586420
You can’t perform that action at this time.
0 commit comments