Check-in [c9001fb21d]
Not logged in
Overview
SHA1 Hash:c9001fb21dacda57c8318e812cf25b020ed3f00c
Date: 2011-08-20 15:43:24
User: kinaba
Comment:514
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Added SRM/514-U/1A.cpp version [3c6459225e1fc2fa]

> 1 #include <iostream> > 2 #include <sstream> > 3 #include <iomanip> > 4 #include <vector> > 5 #include <string> > 6 #include <map> > 7 #include <set> > 8 #include <algorithm> > 9 #include <numeric> > 10 #include <iterator> > 11 #include <functional> > 12 #include <complex> > 13 #include <queue> > 14 #include <stack> > 15 #include <cmath> > 16 #include <cassert> > 17 #include <cstring> > 18 using namespace std; > 19 typedef long long LL; > 20 typedef complex<double> CMP; > 21 > 22 class MagicalGirlLevelOneDivOne { public: > 23 string isReachable(vector <int> jumpTypes, int x, int y) > 24 { > 25 bool hasEven = false; > 26 for(int i=0; i<jumpTypes.size(); ++i) > 27 if( jumpTypes[i]%2 == 0 ) > 28 hasEven = true; > 29 if( hasEven ) > 30 return "YES"; > 31 else > 32 return (x+y)%2==0 ? "YES" : "NO"; > 33 } > 34 }; > 35 > 36 // BEGIN CUT HERE > 37 #include <ctime> > 38 double start_time; string timer() > 39 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) > 40 template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) > 41 { os << "{ "; > 42 for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) > 43 os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return > 44 void verify_case(const string& Expected, const string& Received) { > 45 bool ok = (Expected == Received); > 46 if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() > 47 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' > 48 #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock( > 49 #define END verify_case(_, MagicalGirlLevelOneDivOne().isReachable(jumpType > 50 int main(){ > 51 > 52 CASE(0) > 53 int jumpTypes_[] = {2}; > 54 vector <int> jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeo > 55 int x = 5; > 56 int y = 4; > 57 string _ = "YES"; > 58 END > 59 CASE(1) > 60 int jumpTypes_[] = {3}; > 61 vector <int> jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeo > 62 int x = 5; > 63 int y = 4; > 64 string _ = "NO"; > 65 END > 66 CASE(2) > 67 int jumpTypes_[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; > 68 vector <int> jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeo > 69 int x = 1000000000; > 70 int y = -999999999; > 71 string _ = "YES"; > 72 END > 73 CASE(3) > 74 int jumpTypes_[] = {999999999}; > 75 vector <int> jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeo > 76 int x = 999999999; > 77 int y = 0; > 78 string _ = "NO"; > 79 END > 80 /* > 81 CASE(4) > 82 int jumpTypes_[] = ; > 83 vector <int> jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeo > 84 int x = ; > 85 int y = ; > 86 string _ = ; > 87 END > 88 CASE(5) > 89 int jumpTypes_[] = ; > 90 vector <int> jumpTypes(jumpTypes_, jumpTypes_+sizeof(jumpTypes_)/sizeo > 91 int x = ; > 92 int y = ; > 93 string _ = ; > 94 END > 95 */ > 96 } > 97 // END CUT HERE

Added SRM/514-U/2A-U.cpp version [757c488211084a3d]

> 1 #include <iostream> > 2 #include <sstream> > 3 #include <iomanip> > 4 #include <vector> > 5 #include <string> > 6 #include <map> > 7 #include <set> > 8 #include <algorithm> > 9 #include <numeric> > 10 #include <iterator> > 11 #include <functional> > 12 #include <complex> > 13 #include <queue> > 14 #include <stack> > 15 #include <cmath> > 16 #include <cassert> > 17 #include <cstring> > 18 using namespace std; > 19 typedef long long LL; > 20 typedef complex<double> CMP; > 21 > 22 static const int MODVAL = 1000000007; > 23 > 24 struct UnionFind > 25 { > 26 vector<int> uf, sz; > 27 int nc; > 28 > 29 UnionFind(int N): uf(N), sz(N,1), nc(N) > 30 { for(int i=0; i<N; ++i) uf[i] = i; } > 31 int size() > 32 { return nc; } > 33 int Find(int a) > 34 { return uf[a]==a ? a : uf[a]=Find(uf[a]); } > 35 bool Union(int a, int b) > 36 { > 37 a = Find(a); > 38 b = Find(b); > 39 if( a != b ) > 40 { > 41 if( sz[a] >= sz[b] ) swap(a, b); > 42 uf[a] = b; > 43 sz[b] += sz[a]; > 44 --nc; > 45 } > 46 return (a!=b); > 47 } > 48 }; > 49 > 50 struct mint > 51 { > 52 int val; > 53 mint():val(0){} > 54 mint(int x):val(x%MODVAL) {} > 55 mint(LL x):val(x%MODVAL) {} > 56 }; > 57 mint operator+(mint x, mint y) { return x.val+y.val; } > 58 mint operator-(mint x, mint y) { return x.val-y.val+MODVAL; } > 59 mint operator*(mint x, mint y) { return LL(x.val)*y.val; } > 60 mint POW(mint x, int e) { > 61 mint v = 1; > 62 for(;e;x=x*x,e>>=1) > 63 if(e&1) > 64 v=v*x; > 65 return v; > 66 } > 67 > 68 class MagicalGirlLevelTwoDivOne { public: > 69 int theCount(vector <string> palette, int n, int m) > 70 { > 71 if( (n^m)&1 ) > 72 return 0; > 73 int H = palette.size(); > 74 int W = palette[0].size(); > 75 > 76 #define key(y,x) (2+(y)*W+(x)) > 77 > 78 UnionFind uf(W*H+2); > 79 for(int y=0; y<H; ++y) > 80 for(int x=0; x<W; ++x) > 81 { > 82 if( palette[y][x] != '.' ) > 83 uf.Union(key(y,x), (palette[y][x]-'0')%2); // 0: > 84 if( y-n>=0 ) > 85 uf.Union(key(y,x), key(y-n,x)); > 86 if( x-m>=0 ) > 87 uf.Union(key(y,x), key(y,x-m)); > 88 } > 89 > 90 if( uf.Find(0) == uf.Find(1) ) > 91 return 0; > 92 > 93 vector< vector<int> > dep(n, vector<int>(m)); > 94 vector< vector<int> > stt(n, vector<int>(m)); > 95 for(int y=0; y<n; ++y) > 96 for(int x=0; x<m; ++x) > 97 { > 98 for(int yy=y; yy<H; yy+=n) > 99 for(int xx=x; xx<W; xx+=m) > 100 if(palette[yy][xx] == '.') > 101 dep[y][x]++; > 102 int k = uf.Find(key(y,x)); > 103 if( k == uf.Find(0) ) > 104 stt[y][x] = 0; > 105 else if( k == uf.Find(1) ) > 106 stt[y][x] = 1; > 107 else > 108 stt[y][x] = 2; > 109 } > 110 > 111 memo.assign(1024*10, -1); > 112 return rec(dep, stt, n, m, 0, 0); > 113 } > 114 > 115 vector<int> memo; > 116 int rec(const vector< vector<int> >& dep, const vector< vector<int> >& s > 117 int y, int status) > 118 { > 119 if( y == H ) > 120 if( status == (1<<W)-1 ) > 121 return 1; > 122 else > 123 return 0; > 124 int me = status*H+y; > 125 if( memo[me] != -1 ) > 126 return memo[me]; > 127 > 128 mint total; > 129 for(int bits=0; bits<(1<<W); ++bits) > 130 { > 131 mint cur(1); > 132 int odd = 0; > 133 for(int x=0; x<W; ++x) > 134 if( (bits>>x)&1 ) > 135 ++odd; > 136 int odddep = 0; > 137 int evendep = 0; > 138 if(odd%2 == 0) > 139 goto next; > 140 for(int x=0; x<W; ++x) > 141 if( stt[y][x] != 2 && stt[y][x] != ((bits>>x)&1) > 142 goto next; > 143 for(int x=0; x<W; ++x) > 144 { > 145 int d = dep[y][x]; > 146 (((bits>>x)&1) ? odddep : evendep) += d; > 147 } > 148 cur = cur * POW(5, odddep); > 149 cur = cur * POW(4,evendep); > 150 cur = cur * rec(dep, stt, H, W, y+1, status^bits); > 151 total = total + cur; > 152 next:; > 153 } > 154 return memo[me] = total.val; > 155 } > 156 }; > 157 > 158 // BEGIN CUT HERE > 159 #include <ctime> > 160 double start_time; string timer() > 161 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) > 162 template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) > 163 { os << "{ "; > 164 for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) > 165 os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return > 166 void verify_case(const int& Expected, const int& Received) { > 167 bool ok = (Expected == Received); > 168 if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() > 169 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' > 170 #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock( > 171 #define END verify_case(_, MagicalGirlLevelTwoDivOne().theCount(palette, n, > 172 int main(){ > 173 > 174 CASE(0) > 175 string palette_[] = {"12", > 176 "2."}; > 177 vector <string> palette(palette_, palette_+sizeof(palette_)/sizeof(*pa > 178 int n = 2; > 179 int m = 2; > 180 int _ = 5; > 181 END > 182 CASE(1) > 183 string palette_[] = {"21", > 184 "1."}; > 185 vector <string> palette(palette_, palette_+sizeof(palette_)/sizeof(*pa > 186 int n = 2; > 187 int m = 2; > 188 int _ = 4; > 189 END > 190 CASE(2) > 191 string palette_[] = {"...", > 192 "...", > 193 "..."}; > 194 vector <string> palette(palette_, palette_+sizeof(palette_)/sizeof(*pa > 195 int n = 1; > 196 int m = 1; > 197 int _ = 1953125; > 198 END > 199 CASE(3) > 200 string palette_[] = {"..58..", > 201 "..47.."}; > 202 vector <string> palette(palette_, palette_+sizeof(palette_)/sizeof(*pa > 203 int n = 2; > 204 int m = 3; > 205 int _ = 0; > 206 END > 207 CASE(4) > 208 string palette_[] = {"...1.2.3", > 209 "4.5.6...", > 210 "...7.8.9", > 211 "1.2.3..."}; > 212 vector <string> palette(palette_, palette_+sizeof(palette_)/sizeof(*pa > 213 int n = 4; > 214 int m = 4; > 215 int _ = 886073030; > 216 END > 217 CASE(5) > 218 string palette_[] = {"....................", > 219 "....................", > 220 "....................", > 221 "....................", > 222 "....................", > 223 "....................", > 224 "....................", > 225 "....................", > 226 "....................", > 227 "....................", > 228 "....................", > 229 "....................", > 230 "....................", > 231 "....................", > 232 "....................", > 233 "....................", > 234 "....................", > 235 "....................", > 236 "....................", > 237 "...................."}; > 238 vector <string> palette(palette_, palette_+sizeof(palette_)/sizeof(*pa > 239 int n = 10; > 240 int m = 10; > 241 int _ = 240076532; > 242 END > 243 /* > 244 CASE(6) > 245 string palette_[] = ; > 246 vector <string> palette(palette_, palette_+sizeof(palette_)/sizeof(*pa > 247 int n = ; > 248 int m = ; > 249 int _ = ; > 250 END > 251 CASE(7) > 252 string palette_[] = ; > 253 vector <string> palette(palette_, palette_+sizeof(palette_)/sizeof(*pa > 254 int n = ; > 255 int m = ; > 256 int _ = ; > 257 END > 258 */ > 259 } > 260 // END CUT HERE