結果
問題 | No.693 square1001 and Permutation 2 |
ユーザー |
|
提出日時 | 2018-07-13 23:25:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 848 bytes |
コンパイル時間 | 1,699 ms |
コンパイル使用メモリ | 171,288 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-09 05:43:29 |
合計ジャッジ時間 | 2,288 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
ソースコード
#include "bits/stdc++.h"using namespace std;typedef long long ll;#define INF (1<<30)#define INFLL (1ll<<60)typedef pair<double, int> P;typedef pair<int, P> E;#define MOD (1000000007ll)#define l_ength size#define EPS (1e-10)void add_mod(ll &a, ll b){a += b;a %= MOD;}void mul_mod(ll &a, ll b){a *= b;a %= MOD;}string s;stack<int> t;int p[123];int calc(int l, int r){int ret=0,d=1,v,i;for(i=l; i<=r; ++i){if(s[i] == '+'){d = 1;continue;}else if(s[i] == '-'){d = -1;continue;}if(s[i] == '('){v = calc(i+1,p[i]-1);i = p[i];}else{v = s[i]-'0';}ret += d*v;}return ret;}int main(void){int n,a[123456],i,ans=0;cin >> n;for(i=0; i<n; ++i){cin >> a[i];--a[i];}sort(a,a+n);for(i=0; i<n; ++i){ans += abs(a[i]-i);}cout << ans << endl;return 0;}