Submission #1328357

#TimeUsernameProblemLanguageResultExecution timeMemory
1328357SmuggingSpunMisspelling (JOI22_misspelling)C++20
100 / 100
707 ms198804 KiB
#include<bits/stdc++.h>
#define taskname "C"
using namespace std;
const int mod = 1e9 + 7;
template<class T>void maximize(T& a, T b){
  if(a < b){
    a = b;
  }
}
void add(int& a, int b){
  if((a += b) >= mod){
    a -= mod;
  }
}
void sub(int& a, int b){
  if((a -= b) < 0){
    a += mod;
  }
}
int get_sub(int a, int b){
  return (a -= b) < 0 ? a + mod : a;
}
int n, m;
namespace sub12{
  const int lim = 202;
  int lar[lim], sma[lim], f[lim][lim][27], nf[lim][lim][27];
  void solve(){
    memset(lar, 0, sizeof(lar));
    memset(sma, 0, sizeof(sma));
    for(int _ = 0; _ < m; _++){
      int a, b;
      cin >> a >> b;
      if(a < b){
        maximize(lar[a], b);
      }
      else{
        maximize(sma[b], a);
      }
    }
    for(int i = 0; i <= n; i++){
      for(int j = 0; j <= n; j++){
        iota(f[i][j], f[i][j] + 27, 0);
      }
    }
    for(int i = n; i > 1; i--){
      memset(nf, 0, sizeof(nf));
      for(int j = 0; j <= n; j++){
        for(int k = 0; k <= n; k++){
          for(int pre = 1; pre < 27; pre++){
            nf[j][k][pre] = get_sub(f[max(j, lar[i])][max(k, sma[i])][pre], f[max(j, lar[i])][max(k, sma[i])][pre - 1]);
            if(i > j){
              add(nf[j][k][pre], f[lar[i]][sma[i]][pre - 1]);
            }
            if(i > k){
              add(nf[j][k][pre], get_sub(f[lar[i]][sma[i]][26], f[lar[i]][sma[i]][pre]));
            }
          }
        }
      }
      memcpy(f, nf, sizeof(f));
      for(int j = 0; j <= n; j++){
        for(int k = 0; k <= n; k++){
          for(int t = 1; t < 27; t++){
            add(f[j][k][t], f[j][k][t - 1]);
          }
        }
      }
    }
    cout << f[lar[1]][sma[1]][26];
  }
}
namespace sub345{
  const int lim = 5e5 + 5;
  struct DataStructure{
    int sum;
    vector<pair<int, int>>item;
    DataStructure(){
      sum = 0;
    }
    void add_item(int p, int v){
      item.push_back(make_pair(p, v));
      add(sum, v);
    }
    void remove_items(int p){
      while(!item.empty() && item.back().first <= p){
        sub(sum, item.back().second);
        item.pop_back();
      }
    }
  };
  DataStructure ds[26][2];
  int lar[lim], sma[lim], temp[26][2];
  void solve(){
    memset(lar, 0, sizeof(lar));
    memset(sma, 0, sizeof(sma));
    for(int _ = 0; _ < m; _++){
      int a, b;
      cin >> a >> b;
      if(a < b){
        maximize(lar[a], b);
      }
      else{
        maximize(sma[b], a);
      }
    }
    for(int i = 0; i < 26; i++){
      ds[i][0].add_item(n + 1, 1);
    }
    for(int i = n; i > 1; i--){
      for(int j = 0; j < 26; j++){
        temp[j][0] = ds[j][0].sum;
        temp[j][1] = ds[j][1].sum;
        ds[j][0].remove_items(lar[i - 1]);
        ds[j][1].remove_items(sma[i - 1]);
      }
      if(i > sma[i - 1]){
        for(int j = 0, acc = 0; j < 26; j++){
          ds[j][1].add_item(i, acc);
          add(acc, temp[j][0]);
          add(acc, temp[j][1]);
        }
      }
      if(i > lar[i - 1]){
        for(int j = 25, acc = 0; j > -1; j--){
          ds[j][0].add_item(i, acc);
          add(acc, temp[j][0]);
          add(acc, temp[j][1]);
        }
      }
    }
    int ans = 0;
    for(int i = 0; i < 26; i++){
      add(ans, ds[i][0].sum);
      add(ans, ds[i][1].sum);
    }
    cout << ans;
  }
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
  cin >> n >> m;
  if(n <= 200){
    sub12::solve();
  }
  else{
    sub345::solve();
  }
}

Compilation message (stderr)

misspelling.cpp: In function 'int main()':
misspelling.cpp:142:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  142 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...