prestige

Untitled

Dec 30th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. //#pragma comment(linker, "/STACK:36777216")
  2. #include <algorithm>
  3. #include <bitset>
  4. #include <cassert>
  5. #include <cmath>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <iostream>
  10. #include <list>
  11. #include <map>
  12. #include <queue>
  13. #include <set>
  14. #include <string>
  15. #include <sstream>
  16. #include <vector>
  17. #include <complex>
  18. #include <ctime>
  19. #include <stack>
  20.  
  21. //#include <bits/stdc++.h>
  22. //#include <ext/pb_ds/assoc_container.hpp>
  23. //#include <ext/pb_ds/tree_policy.hpp>
  24.  
  25. using namespace std;
  26. //using namespace __gnu_pbds;
  27.  
  28. typedef long long ll;
  29. typedef unsigned long long ull;
  30. typedef vector<int> VI;
  31. typedef vector< VI > VVI;
  32. typedef pair<int, int> PII;
  33. typedef vector<PII> VPII;
  34.  
  35. #define REP(i, n) for(int i = 0; i < (n); ++i)
  36. #define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
  37. #define FOR(i, x, y) for(int i = (x); i <= (y); ++i)
  38. #define RFOR(i, y, x) for(int i = (x); i >= (y); --i)
  39. #define SZ(a) (int)(a).size()
  40. #define ALL(a) (a).begin(),(a).end()
  41. #define SORT(a) sort(ALL(a))
  42. #define CLEAR(x) memset(x, 0, sizeof x);
  43. #define COPY(FROM, TO) memcpy(TO, FROM, sizeof TO);
  44. #define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
  45. #define pb push_back
  46. #define mk make_pair
  47. #define sqr(x) ((x)*(x))
  48. #define X first
  49. #define Y second
  50. //typedef tree<int, null_type, less<int>,
  51. // rb_tree_tag, tree_order_statistics_node_update> order_set;
  52.  
  53. const long double PI = acos(-1.0);
  54. const double EPS = 1E-6;
  55. const int INF = 2 * (1e+9) + 1;
  56. const int MAXN = 3 * 100000001;
  57. const int MOD = (1e+9) + 7;
  58.  
  59. int n, m, t;
  60. int u[301];
  61. int a[100100];
  62. int pp[301][301];
  63. void dfs (int v, VI & p) {
  64. p[v] = 1;
  65. REP (i, n) {
  66. if (pp[v][i] == 0) {
  67. dfs (i, p);
  68. }
  69. }
  70. p[v] = 2;
  71. }
  72. int main () {
  73. cin >> n;
  74. REP (i, n) cin >> a[i];
  75. cout << "11111111";
  76. REP (i, n) {
  77. REP (j, n) {
  78. char c; cin >> c;
  79. pp[i][j] = (c - '0');
  80. }
  81. }
  82. REP (i, n) {
  83. REP (j, n) {
  84. cout << pp[i][j];
  85. }
  86. }
  87. REP (i, n) {
  88. VPII t;
  89. REP (j, n) {
  90. if (!u[j]) {
  91. t.pb(mk(-a[j], j));
  92. }
  93. }
  94. SORT(t);
  95. VI p(n, 0);
  96. dfs (i, p);
  97. REP (j, SZ(t)) {
  98. if (p[t[j].second]) {
  99. u[t[j].second] = 1;
  100. swap (a[i], a[t[j].second]);
  101. }
  102. }
  103. }
  104. REP (i, n) {
  105. cout << a[i] << " ";
  106. }
  107. }
  108. /*
  109. 7
  110. 5 2 4 3 6 7 1
  111. 0001001
  112. 0000000
  113. 0000010
  114. 1000001
  115. 0000000
  116. 0010000
  117. 1001000
  118. */
Advertisement
Add Comment
Please, Sign In to add comment