Submission #630783

# Submission time Handle Problem Language Result Execution time Memory
630783 2022-08-17T03:25:58 Z iee Clickbait (COCI18_clickbait) C++17
120 / 120
39 ms 33704 KB
// iee
#include <bits/stdc++.h>
#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using db = double;
using ld = long double;
#define py puts("YES")
#define pn puts("NO")
#define pf puts("-1")
#define hh puts("")
#define fi first
#define se second
#define mkp make_pair
#define re =RD()
#define rd RD()
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define ep emplace
#define ci const int
#define vi vector<int>
#define fn for(int i=1;i<=n;++i)
#define rep(stO,a,b) for(int stO=(a);stO<=(b);stO++)
#define Rep(stO,a,b) for(int stO=(a);stO<(b);stO++)
#define per(Orz,a,b) for(int Orz=(a);Orz>=(b);Orz--)
#define ina int n,a[N];
#define rna n=RD();fn a[i]=RD();
using namespace std;
int qpow(int a, int b, int p) { int res = 1 % p; while (b) { if (b % 2) res = 1ll * res * a % p; a = 1ll * a * a % p; b /= 2; } return res; }
int RD() { int x = 0, f = 1, ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; }
//ci p = 998244353 1000000007; int fac[N], inv[N], ifac[N]; int binom(int x, int y, int MOD = p) { if (x < y) return 0; return 1ll * fac[x] * ifac[y] % p * ifac[x - y] % p; } void init(int LIM = N - 1, int MOD = p) { fac[0] = ifac[0] = inv[1] = 1; rep(i, 1, LIM) fac[i] = 1ll * fac[i - 1] * i % MOD; rep(i, 2, LIM) inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD; rep(i, 1, LIM) ifac[i] = 1ll * ifac[i - 1] * inv[i] % MOD; }
void work(int);

signed main() { int CASINPUT = 1;
  string op = R"(
                 )";if (op.size() == 19) cin >> CASINPUT; rep(CUR, 1, CASINPUT) work(CUR); }

ci N = 1005, M = 1e6 + 5;
vector<pii> e[M];
vi ans;
char a[N][N];
int col[N][N];
void dfs(int u) {
 for (auto v: e[u]) dfs(v.fi);
 ans.pb(u);
}
ci nxt[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
void work(int CASE) {
 int n re, m re;
 int num = 0;
 Rep(i,0,n)scanf("%s",a[i]);
 memset(col,-1,sizeof col);//col[i][j] = -1;
 Rep(i,0,n)Rep(j,0,m)if(isdigit(a[i][j])&&(j==0 || !isdigit(a[i][j-1]))){
  ++num;
  int c = 0;
  Rep(k,j,m) if(isdigit(a[i][k])) c = c * 10 + (a[i][k]-'0'); else break;
  --c;
  queue<pii> q;q.ep(i,j);
  col[i][j] = c;
  while (!q.empty()) {
   int x,y;tie(x,y) = q.front();q.pop();
   if (x>0 && a[x - 1][y] != '-' && col[x - 1][y] == -1)col[x - 1][y] = c,q.ep(x - 1, y);
   else if(x>0) col[x - 1][y] = c;
   
   if (x<n-1 && a[x + 1][y] != '-' && col[x+1][y] == -1)col[x+1][y] = c,q.ep(x + 1,y);
   else if(x<n-1) col[x+1][y] = c;
   
   if(y >0 &&a[x][y - 1] != '|'&&col[x][y - 1]==-1)col[x][y - 1]=c,q.ep(x,y - 1);
   else if(y>0) col[x][y-1] = c;
   
   if(y <m-1&&a[x][y + 1]!='|' && col[x][y+1] == -1)col[x][y +1] =c ,q.ep(x,y +1);
   else if(y< m-1)col[x][y + 1]=c;
   
   for(int dx:{-1,1})for(int dy:{-1,1}){
    int nx=x+dx,ny=y+dy;if(nx>=0&&nx<n&&ny>=0&&ny<m && a[nx][ny]=='+')col[nx][ny] = c;
   }
  }
 }
 // Rep(i,0,n){
  // Rep(j,0,m)debug("%3lld",col[i][j]);debug("\n");
 // }
 Rep(i,0,n)Rep(j,0,m){
  if(col[i][j] != -1)continue;
  if(a[i][j] != '+' && a[i][j] != '-' && a[i][j] != '|') continue;
  queue<pii>q;q.ep(i,j);
  int c1 = -1,c2 = -1;pii x1(114,514),x2(1919,810);col[i][j] = 1e9;
  while(!q.empty()){
   int x,y;tie(x,y) = q.front();q.pop();
   Rep(d,0,4){
    int nx=x+nxt[d][0], ny=y+nxt[d][1];
    if(nx < 0 || nx >= n || ny < 0 || ny >= m)continue;
    if(a[nx][ny] != '.' && col[nx][ny] == -1)col[nx][ny] = 1e9,q.ep(nx,ny);
    else if(a[nx][ny] != '.' && col[nx][ny] != 1e9){
     if(c1 == -1)c1=col[nx][ny],x1 = mkp(nx,ny);
     else c2=col[nx][ny],x2 = mkp(nx,ny);
    }
   }
  }
  if(x1.fi > x2.fi)swap(x1,x2), swap(c1,c2);
  e[c1].eb(c2, x1.fi);
 }
 Rep(i,0,num)sort(all(e[i]),[](pii x,pii y){return x.se>y.se;});
 dfs(0);
 for(int x: ans)cout<<x+1<<endl;
}

Compilation message

clickbait.cpp: In function 'void work(long long int)':
clickbait.cpp:54:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  Rep(i,0,n)scanf("%s",a[i]);
      |            ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31700 KB Output is correct
2 Correct 15 ms 31700 KB Output is correct
3 Correct 16 ms 31728 KB Output is correct
4 Correct 15 ms 31596 KB Output is correct
5 Correct 15 ms 31704 KB Output is correct
6 Correct 16 ms 31728 KB Output is correct
7 Correct 16 ms 31700 KB Output is correct
8 Correct 15 ms 31992 KB Output is correct
9 Correct 16 ms 32596 KB Output is correct
10 Correct 39 ms 33704 KB Output is correct